summaryrefslogtreecommitdiffhomepage
path: root/dev/LibC++
diff options
context:
space:
mode:
authorAmlal <amlal.elmahrouss@icloud.com>2025-01-21 20:23:15 +0100
committerAmlal <amlal.elmahrouss@icloud.com>2025-01-21 20:23:15 +0100
commita133c71c22b8f9576bfc667f000c7c764d4505c8 (patch)
tree03b3edef5ebf7e0182b4ae73cd5d38c370ed947c /dev/LibC++
ADD: NeKernel Toolchain 0.0.9 (Beta Release)
Signed-off-by: Amlal <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/LibC++')
-rw-r--r--dev/LibC++/.gitignore1
-rw-r--r--dev/LibC++/base_alloc.h49
-rw-r--r--dev/LibC++/base_exception.h30
-rw-r--r--dev/LibC++/base_math.h62
-rw-r--r--dev/LibC++/defines.h96
-rw-r--r--dev/LibC++/filesystem.h18
-rwxr-xr-xdev/LibC++/make_cxx_headers.sh13
-rw-r--r--dev/LibC++/power64.inc35
-rw-r--r--dev/LibC++/process_base.h21
-rw-r--r--dev/LibC++/utility.h33
10 files changed, 358 insertions, 0 deletions
diff --git a/dev/LibC++/.gitignore b/dev/LibC++/.gitignore
new file mode 100644
index 0000000..5fa1170
--- /dev/null
+++ b/dev/LibC++/.gitignore
@@ -0,0 +1 @@
+stdcxx/
diff --git a/dev/LibC++/base_alloc.h b/dev/LibC++/base_alloc.h
new file mode 100644
index 0000000..3958325
--- /dev/null
+++ b/dev/LibC++/base_alloc.h
@@ -0,0 +1,49 @@
+/* -------------------------------------------
+
+ Copyright (C) 2024 Amlal EL Mahrouss, all rights reserved.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <LibC++/defines.h>
+
+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.h b/dev/LibC++/base_exception.h
new file mode 100644
index 0000000..29d7990
--- /dev/null
+++ b/dev/LibC++/base_exception.h
@@ -0,0 +1,30 @@
+/* -------------------------------------------
+
+ Copyright (C) 2024 Amlal EL Mahrouss, all rights reserved.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <LibC++/defines.h>
+#include <LibC++/process_base.h>
+
+namespace std::base_exception
+{
+ 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::base_exception
diff --git a/dev/LibC++/base_math.h b/dev/LibC++/base_math.h
new file mode 100644
index 0000000..9d131d4
--- /dev/null
+++ b/dev/LibC++/base_math.h
@@ -0,0 +1,62 @@
+/* -------------------------------------------
+
+ Copyright (C) 2024 Amlal EL Mahrouss, all rights reserved.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <LibC++/defines.h>
+
+/// @file Math.h
+/// @brief Math functions.
+
+#ifdef __ZKA_USE_DOUBLE__
+typedef double real_type;
+#else
+typedef float real_type;
+#endif
+
+namespace std::base_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::base_math
diff --git a/dev/LibC++/defines.h b/dev/LibC++/defines.h
new file mode 100644
index 0000000..6caf9d3
--- /dev/null
+++ b/dev/LibC++/defines.h
@@ -0,0 +1,96 @@
+/* -------------------------------------------
+
+ Copyright (C) 2024 Amlal EL Mahrouss, all rights reserved.
+
+------------------------------------------- */
+
+#ifndef __LIBCOMPILER_DEFINES_H__
+#define __LIBCOMPILER_DEFINES_H__
+
+extern "C"
+{
+#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.h>
+#elif defined(__LIBCOMPILER__)
+#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__
+
+#endif /* __LIBCOMPILER_DEFINES_H__ */
diff --git a/dev/LibC++/filesystem.h b/dev/LibC++/filesystem.h
new file mode 100644
index 0000000..4d16819
--- /dev/null
+++ b/dev/LibC++/filesystem.h
@@ -0,0 +1,18 @@
+/* -------------------------------------------
+
+ Copyright (C) 2024 Amlal EL Mahrouss, all rights reserved.
+
+------------------------------------------- */
+
+#ifndef __LIBCOMPILER_FS_H__
+#define __LIBCOMPILER_FS_H__
+
+namespace std
+{
+ class path;
+ class filesystem_error;
+ class directory_entry;
+ class directory_iterator;
+} // namespace std
+
+#endif // __LIBCOMPILER_FS_H__ \ No newline at end of file
diff --git a/dev/LibC++/make_cxx_headers.sh b/dev/LibC++/make_cxx_headers.sh
new file mode 100755
index 0000000..cdb89f6
--- /dev/null
+++ b/dev/LibC++/make_cxx_headers.sh
@@ -0,0 +1,13 @@
+#! /bin/bash
+
+outputDir=stdcxx/
+
+mkdir -p $outputDir
+
+for f in *.h; do
+
+#This line splits the file name on the delimiter "."
+baseName=`echo $f | cut -d "." -f 1`
+cp $f $outputDir$baseName
+
+done
diff --git a/dev/LibC++/power64.inc b/dev/LibC++/power64.inc
new file mode 100644
index 0000000..f3fd0ee
--- /dev/null
+++ b/dev/LibC++/power64.inc
@@ -0,0 +1,35 @@
+# Path: LibC++/power.inc
+# Language: LibCompiler POWER Assembly support for GNU.
+# Build Date: 2024-6-4
+
+%ifdef __LIBCOMPILER__
+
+%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
diff --git a/dev/LibC++/process_base.h b/dev/LibC++/process_base.h
new file mode 100644
index 0000000..35e551b
--- /dev/null
+++ b/dev/LibC++/process_base.h
@@ -0,0 +1,21 @@
+/* -------------------------------------------
+
+ Copyright (C) 2024 Amlal EL Mahrouss, all rights reserved.
+
+------------------------------------------- */
+
+#pragma once
+
+/// @brief CRT exit, with exit code (!!! exits all threads. !!!)
+/// @param code the exit code.
+/// @return the return > 0 for non successful.
+extern "C" int exit(int code);
+
+/// @brief Standard C++ namespace
+namespace std::process_base
+{
+ inline int exit(int code)
+ {
+ exit(code);
+ }
+} // namespace std::process_base
diff --git a/dev/LibC++/utility.h b/dev/LibC++/utility.h
new file mode 100644
index 0000000..83d318f
--- /dev/null
+++ b/dev/LibC++/utility.h
@@ -0,0 +1,33 @@
+/* -------------------------------------------
+ \
+ Copyright (C) 2024 Amlal EL Mahrouss, all rights reserved. \
+ \
+------------------------------------------- */
+
+#ifndef LIBCXX_UTILITY_H
+#define LIBCXX_UTILITY_H
+
+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 // LIBCXX_UTILITY_H