Refactor filesystem & stl code

This commit is contained in:
EnderIce2
2024-05-18 07:42:01 +03:00
parent 77a291d08b
commit 6801475243
186 changed files with 15784 additions and 9746 deletions

View File

@ -42,12 +42,31 @@ namespace std
return d_last;
}
template <typename T>
void swap(T &a, T &b)
template <typename InputIt, typename OutputIt, typename UnaryOperation>
OutputIt transform(InputIt first, InputIt last, OutputIt result, UnaryOperation op)
{
T temp = move(a);
a = move(b);
b = move(temp);
while (first != last)
{
*result = op(*first);
++first;
++result;
}
return result;
};
template <class T>
void swap(T &a, T &b) noexcept(std::is_nothrow_move_constructible<T>::value && std::is_nothrow_move_assignable<T>::value)
{
T temp = std::move(a);
a = std::move(b);
b = std::move(temp);
}
template <class T2, std::size_t N>
void swap(T2 (&a)[N], T2 (&b)[N]) noexcept(std::is_nothrow_swappable_v<T2>)
{
for (std::size_t i = 0; i < N; ++i)
std::swap(a[i], b[i]);
}
template <typename T>
@ -193,4 +212,116 @@ namespace std
}
return first;
}
template <class InputIt1, class InputIt2>
constexpr bool equal(InputIt1 first1, InputIt1 last1, InputIt2 first2)
{
while (first1 != last1)
{
if (!(*first1 == *first2))
return false;
++first1;
++first2;
}
return true;
}
template <class ExecutionPolicy, class ForwardIt1, class ForwardIt2>
bool equal(ExecutionPolicy &&policy, ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2)
{
while (first1 != last1)
{
if (!(*first1 == *first2))
return false;
++first1;
++first2;
}
return true;
}
template <class InputIt1, class InputIt2, class BinaryPred>
constexpr bool equal(InputIt1 first1, InputIt1 last1, InputIt2 first2, BinaryPred p)
{
while (first1 != last1)
{
if (!p(*first1, *first2))
return false;
++first1;
++first2;
}
return true;
}
template <class ExecutionPolicy, class ForwardIt1, class ForwardIt2, class BinaryPred>
bool equal(ExecutionPolicy &&policy, ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2, BinaryPred p)
{
while (first1 != last1)
{
if (!p(*first1, *first2))
return false;
++first1;
++first2;
}
return true;
}
template <class InputIt1, class InputIt2>
constexpr bool equal(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2)
{
while (first1 != last1)
{
if (!(*first1 == *first2))
return false;
++first1;
++first2;
}
return true;
}
template <class ExecutionPolicy, class ForwardIt1, class ForwardIt2>
bool equal(ExecutionPolicy &&policy, ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2, ForwardIt2 last2)
{
while (first1 != last1)
{
if (!(*first1 == *first2))
return false;
++first1;
++first2;
}
return true;
}
template <class InputIt1, class InputIt2, class BinaryPred>
constexpr bool equal(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, BinaryPred p)
{
while (first1 != last1)
{
if (!p(*first1, *first2))
return false;
++first1;
++first2;
}
return true;
}
template <class ExecutionPolicy, class ForwardIt1, class ForwardIt2, class BinaryPred>
bool equal(ExecutionPolicy &&policy, ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2, ForwardIt2 last2, BinaryPred p)
{
while (first1 != last1)
{
if (!p(*first1, *first2))
return false;
++first1;
++first2;
}
return true;
}
}

37
include_std/cctype Normal file
View File

@ -0,0 +1,37 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
namespace std
{
inline int tolower(int ch)
{
if (ch >= 'A' && ch <= 'Z')
return ch + ('a' - 'A');
else
return ch;
}
inline int toupper(int ch)
{
if (ch >= 'a' && ch <= 'z')
return ch - ('a' - 'A');
else
return ch;
}
}

View File

@ -17,9 +17,12 @@
#pragma once
#include <cfloat>
#include <type_traits>
namespace std
{
double sin(double x)
constexpr double sin(double x)
{
const int NUM_TERMS = 10;
@ -35,7 +38,7 @@ namespace std
return result;
}
float powf(float base, float exp)
constexpr float powf(float base, float exp)
{
float result = 1.0;
for (int i = 0; i < (int)exp; ++i)
@ -43,7 +46,7 @@ namespace std
return result;
}
double pow(double base, double exp)
constexpr double pow(double base, double exp)
{
double result = 1.0;
for (int i = 0; i < (int)exp; ++i)
@ -51,7 +54,7 @@ namespace std
return result;
}
long double powl(long double base, long double exp)
constexpr long double powl(long double base, long double exp)
{
long double result = 1.0;
for (long i = 0; i < (long)exp; ++i)
@ -59,24 +62,121 @@ namespace std
return result;
}
float fabsf(float num)
constexpr float fabsf(float num)
{
if (num < 0)
return -num;
return num;
}
double fabs(double num)
constexpr double fabs(double num)
{
if (num < 0)
return -num;
return num;
}
long double fabsl(long double num)
constexpr long double fabsl(long double num)
{
if (num < 0)
return -num;
return num;
}
template <class Integer>
constexpr bool isinf(Integer num)
{
union
{
unsigned long u;
double f;
} ieee754;
ieee754.f = num;
bool a = ((unsigned)(ieee754.u >> 32) & 0x7fffffff) == 0x7ff00000;
bool b = ((unsigned)ieee754.u == 0);
return a && b;
}
template <class Integer>
constexpr bool isnan(Integer num)
{
return num != num;
}
template <class Integer>
constexpr double fabs(Integer num)
{
return num < 0 ? -num : num;
}
template <class Integer>
constexpr double remainder(Integer x, Integer y)
{
return x - (int)(x / y) * y;
}
template <class Integer>
constexpr double copysign(Integer mag, Integer sgn)
{
return (sgn < 0) ? -mag : mag;
}
template <class Integer>
constexpr bool signbit(Integer num)
{
return num < 0;
}
template <class Integer>
constexpr double fmod(Integer x, Integer y)
{
#pragma STDC FENV_ACCESS ON
double result = std::remainder(std::fabs(x), y = std::fabs(y));
if (std::signbit(result))
result += (double)y;
return std::copysign(result, x);
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
template <class Integer>
constexpr double ceil(Integer num)
{
// int i = (int)num;
// return i + (i < num);
double remainder = std::fmod((double)num, 1.0);
return num >= 0 ? (remainder == 0 ? num : num + 1 - remainder) : num - remainder;
}
#pragma GCC diagnostic pop
template <class Integer>
constexpr double trunc(Integer num)
{
if (std::isinf(num))
return num;
if (std::isnan(num))
return num;
return static_cast<int>(num);
}
template <class Integer>
constexpr double exp(Integer num)
{
double result = 1.0;
double term = 1.0;
for (int i = 1; i <= 10; ++i)
{
term *= static_cast<double>(num) / i;
result += term;
}
return result;
}
}

21
include_std/coroutine Normal file
View File

@ -0,0 +1,21 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
namespace std
{
/* FIXME: Implement */
}

51
include_std/ctype.h Normal file
View File

@ -0,0 +1,51 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __FENNIX_KERNEL_C_TYPE_H__
#define __FENNIX_KERNEL_C_TYPE_H__
#include <types.h>
START_EXTERNC
int isalnum(int);
int isalpha(int);
int isascii(int);
int isblank(int);
int iscntrl(int);
int isdigit(int);
int isgraph(int);
int islower(int);
int isprint(int);
int ispunct(int);
int isspace(int);
int isupper(int);
int isxdigit(int);
int toascii(int);
int tolower(int);
int toupper(int);
#ifndef __cplusplus /* This conflicts with std */
#define _toupper(c) ((c) - 0x20 * (((c) >= 'a') && ((c) <= 'z')))
#define _tolower(c) ((c) + 0x20 * (((c) >= 'A') && ((c) <= 'Z')))
#endif
END_EXTERNC
#endif // !__FENNIX_KERNEL_C_TYPE_H__

View File

@ -1,69 +0,0 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __FENNIX_KERNEL_CXXABI_H__
#define __FENNIX_KERNEL_CXXABI_H__
#include <types.h>
#include <unwind.h>
#include <typeinfo>
namespace __cxxabiv1
{
#define ATEXIT_MAX_FUNCS 128
typedef unsigned uarch_t;
struct atexit_func_entry_t
{
void (*destructor_func)(void *);
void *obj_ptr;
void *dso_handle;
};
struct __cxa_exception
{
std::type_info *exceptionType;
void (*exceptionDestructor)(void *);
std::terminate_handler unexpectedHandler;
std::terminate_handler terminateHandler;
__cxa_exception *nextException;
int handlerCount;
#ifdef __ARM_EABI_UNWINDER__
__cxa_exception *nextPropagatingException;
int propagationCount;
#else
int handlerSwitchValue;
const unsigned char *actionRecord;
const unsigned char *languageSpecificData;
_Unwind_Ptr catchTemp;
void *adjustedPtr;
#endif
_Unwind_Exception unwindHeader;
};
}
struct __cxa_eh_globals
{
__cxxabiv1::__cxa_exception *caughtExceptions;
unsigned int uncaughtExceptions;
#ifdef __ARM_EABI_UNWINDER__
__cxxabiv1::__cxa_exception *propagatingExceptions;
#endif
};
#endif // !__FENNIX_KERNEL_CXXABI_H__

View File

@ -15,7 +15,17 @@
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef _DLFCN_H
#define _DLFCN_H
#ifndef __FENNIX_KERNEL_DLFCN_H__
#define __FENNIX_KERNEL_DLFCN_H__
#endif // !_DLFCN_H
#include <types.h>
typedef struct
{
const char *dli_fname;
void *dli_fbase;
const char *dli_sname;
void *dli_saddr;
} Dl_info;
#endif // !__FENNIX_KERNEL_DLFCN_H__

View File

@ -15,407 +15,9 @@
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef _ERRNO_H
#define _ERRNO_H
#ifndef __FENNIX_KERNEL_STD_ERRNO_H__
#define __FENNIX_KERNEL_STD_ERRNO_H__
/** Operation not permitted */
#define EPERM 1
#include <interface/errno.h>
/** No such file or directory */
#define ENOENT 2
/** No such process */
#define ESRCH 3
/** Interrupted system call */
#define EINTR 4
/** I/O error */
#define EIO 5
/** No such device or address */
#define ENXIO 6
/** Argument list too long */
#define E2BIG 7
/** Exec format error */
#define ENOEXEC 8
/** Bad file number */
#define EBADF 9
/** No child processes */
#define ECHILD 10
/** Try again */
#define EAGAIN 11
/** Out of memory */
#define ENOMEM 12
/** Permission denied */
#define EACCES 13
/** Bad address */
#define EFAULT 14
/** Block device required */
#define ENOTBLK 15
/** Device or resource busy */
#define EBUSY 16
/** File exists */
#define EEXIST 17
/** Cross-device link */
#define EXDEV 18
/** No such device */
#define ENODEV 19
/** Not a directory */
#define ENOTDIR 20
/** Is a directory */
#define EISDIR 21
/** Invalid argument */
#define EINVAL 22
/** File table overflow */
#define ENFILE 23
/** Too many open files */
#define EMFILE 24
/** Not a typewriter */
#define ENOTTY 25
/** Text file busy */
#define ETXTBSY 26
/** File too large */
#define EFBIG 27
/** No space left on device */
#define ENOSPC 28
/** Illegal seek */
#define ESPIPE 29
/** Read-only file system */
#define EROFS 30
/** Too many links */
#define EMLINK 31
/** Broken pipe */
#define EPIPE 32
/** Math argument out of domain of func */
#define EDOM 33
/** Math result not representable */
#define ERANGE 34
/** Resource deadlock would occur */
#define EDEADLK 35
/** File name too long */
#define ENAMETOOLONG 36
/** No record locks available */
#define ENOLCK 37
/** Function not implemented */
#define ENOSYS 38
/** Directory not empty */
#define ENOTEMPTY 39
/** Too many symbolic links encountered */
#define ELOOP 40
/** No message of desired type */
#define ENOMSG 42
/** Identifier removed */
#define EIDRM 43
/** Channel number out of range */
#define ECHRNG 44
/** Level 2 not synchronized */
#define EL2NSYNC 45
/** Level 3 halted */
#define EL3HLT 46
/** Level 3 reset */
#define EL3RST 47
/** Link number out of range */
#define ELNRNG 48
/** Protocol driver not attached */
#define EUNATCH 49
/** No CSI structure available */
#define ENOCSI 50
/** Level 2 halted */
#define EL2HLT 51
/** Invalid exchange */
#define EBADE 52
/** Invalid request descriptor */
#define EBADR 53
/** Exchange full */
#define EXFULL 54
/** No anode */
#define ENOANO 55
/** Invalid request code */
#define EBADRQC 56
/** Invalid slot */
#define EBADSLT 57
/** Bad font file format */
#define EBFONT 59
/** Device not a stream */
#define ENOSTR 60
/** No data available */
#define ENODATA 61
/** Timer expired */
#define ETIME 62
/** Out of streams resources */
#define ENOSR 63
/** Machine is not on the network */
#define ENONET 64
/** Package not installed */
#define ENOPKG 65
/** Object is remote */
#define EREMOTE 66
/** Link has been severed */
#define ENOLINK 67
/** Advertise error */
#define EADV 68
/** Srmount error */
#define ESRMNT 69
/** Communication error on send */
#define ECOMM 70
/** Protocol error */
#define EPROTO 71
/** Multihop attempted */
#define EMULTIHOP 72
/** RFS specific error */
#define EDOTDOT 73
/** Not a data message */
#define EBADMSG 74
/** Value too large for defined data type */
#define EOVERFLOW 75
/** Name not unique on network */
#define ENOTUNIQ 76
/** File descriptor in bad state */
#define EBADFD 77
/** Remote address changed */
#define EREMCHG 78
/** Can not access a needed shared library */
#define ELIBACC 79
/** Accessing a corrupted shared library */
#define ELIBBAD 80
/** .lib section in a.out corrupted */
#define ELIBSCN 81
/** Attempting to link in too many shared libraries */
#define ELIBMAX 82
/** Cannot exec a shared library directly */
#define ELIBEXEC 83
/** Illegal byte sequence */
#define EILSEQ 84
/** Interrupted system call should be restarted */
#define ERESTART 85
/** Streams pipe error */
#define ESTRPIPE 86
/** Too many users */
#define EUSERS 87
/** Socket operation on non-socket */
#define ENOTSOCK 88
/** Destination address required */
#define EDESTADDRREQ 89
/** Message too long */
#define EMSGSIZE 90
/** Protocol wrong type for socket */
#define EPROTOTYPE 91
/** Protocol not available */
#define ENOPROTOOPT 92
/** Protocol not supported */
#define EPROTONOSUPPORT 93
/** Socket type not supported */
#define ESOCKTNOSUPPORT 94
/** Operation not supported on transport endpoint */
#define EOPNOTSUPP 95
/** Protocol family not supported */
#define EPFNOSUPPORT 96
/** Address family not supported by protocol */
#define EAFNOSUPPORT 97
/** Address already in use */
#define EADDRINUSE 98
/** Cannot assign requested address */
#define EADDRNOTAVAIL 99
/** Network is down */
#define ENETDOWN 100
/** Network is unreachable */
#define ENETUNREACH 101
/** Network dropped connection because of reset */
#define ENETRESET 102
/** Software caused connection abort */
#define ECONNABORTED 103
/** Connection reset by peer */
#define ECONNRESET 104
/** No buffer space available */
#define ENOBUFS 105
/** Transport endpoint is already connected */
#define EISCONN 106
/** Transport endpoint is not connected */
#define ENOTCONN 107
/** Cannot send after transport endpoint shutdown */
#define ESHUTDOWN 108
/** Too many references: cannot splice */
#define ETOOMANYREFS 109
/** Connection timed out */
#define ETIMEDOUT 110
/** Connection refused */
#define ECONNREFUSED 111
/** Host is down */
#define EHOSTDOWN 112
/** No route to host */
#define EHOSTUNREACH 113
/** Operation already in progress */
#define EALREADY 114
/** Operation now in progress */
#define EINPROGRESS 115
/** Stale NFS file handle */
#define ESTALE 116
/** Structure needs cleaning */
#define EUCLEAN 117
/** Not a XENIX named type file */
#define ENOTNAM 118
/** No XENIX semaphores available */
#define ENAVAIL 119
/** Is a named type file */
#define EISNAM 120
/** Remote I/O error */
#define EREMOTEIO 121
/** Quota exceeded */
#define EDQUOT 122
/** No medium found */
#define ENOMEDIUM 123
/** Wrong medium type */
#define EMEDIUMTYPE 124
/** Operation Canceled */
#define ECANCELED 125
/** Required key not available */
#define ENOKEY 126
/** Key has expired */
#define EKEYEXPIRED 127
/** Key has been revoked */
#define EKEYREVOKED 128
/** Key was rejected by service */
#define EKEYREJECTED 129
/** Owner died */
#define EOWNERDEAD 130
/** State not recoverable */
#define ENOTRECOVERABLE 131
#include <types.h>
EXTERNC int *__errno_location(void) __attribute__((const));
#define errno (*__errno_location())
#ifdef __cplusplus
extern "C"
{
#endif
const char *strerror(int errnum);
#ifdef __cplusplus
}
#endif
#endif // !_ERRNO_H
#endif // !__FENNIX_KERNEL_STD_ERRNO_H__

View File

@ -26,16 +26,22 @@ namespace std
{
public:
exception() noexcept {}
virtual ~exception() noexcept;
exception(const exception &) = default;
exception &operator=(const exception &) = default;
exception(exception &&) = default;
exception &operator=(exception &&) = default;
virtual const char *what() const noexcept;
exception(const exception &) noexcept = default;
virtual ~exception() noexcept = default;
exception &operator=(const exception &) noexcept = default;
virtual const char *what() const noexcept { return "Exception"; }
};
typedef void (*terminate_handler)();
typedef void (*unexpected_handler)();
[[noreturn]] void terminate() noexcept;
std::terminate_handler set_terminate(std::terminate_handler f) noexcept;
std::terminate_handler get_terminate() noexcept;
[[noreturn]] void unexpected();
std::unexpected_handler set_unexpected(std::unexpected_handler f) noexcept;
std::unexpected_handler get_unexpected() noexcept;
}
#endif // !__FENNIX_KERNEL_EXCEPTION_H__

View File

@ -17,9 +17,13 @@
#pragma once
#include <types.h>
#include <algorithm>
#include <typeinfo>
namespace std
{
template <typename T>
template <typename T = void>
struct equal_to
{
bool operator()(const T &lhs, const T &rhs) const
@ -58,4 +62,193 @@ namespace std
return static_cast<size_t>(hash);
}
};
template <class T>
class reference_wrapper;
template <class>
class function; /* undefined */
template <class R, class... Args>
class function<R(Args...)>
{
private:
class impl_base
{
public:
virtual ~impl_base() = default;
virtual R invoke(Args...) const = 0;
#ifdef __GXX_RTTI
virtual const std::type_info &target_type() const noexcept = 0;
#endif
virtual impl_base *clone() const = 0;
};
template <class F>
class impl : public impl_base
{
public:
F _f;
template <class G>
impl(G &&f)
: _f(std::forward<G>(f))
{
}
R invoke(Args... args) const override
{
return _f(std::forward<Args>(args)...);
}
#ifdef __GXX_RTTI
const std::type_info &target_type() const noexcept override
{
return typeid(F);
}
#endif
impl_base *clone() const override
{
return new impl<F>(_f);
}
};
impl_base *_ptr;
public:
using result_type = R;
function() noexcept
: _ptr(nullptr)
{
}
function(std::nullptr_t) noexcept
: _ptr(nullptr)
{
}
function(const function &other)
: _ptr(other._ptr)
{
}
function(function &&other) noexcept
: _ptr(other._ptr)
{
other._ptr = nullptr;
}
template <class F>
function(F &&f)
: _ptr(new impl<F>(std::forward<F>(f)))
{
}
~function()
{
delete _ptr;
}
function &operator=(const function &other)
{
if (this != &other)
{
delete _ptr;
_ptr = other._ptr ? other._ptr->clone() : nullptr;
}
return *this;
}
function &operator=(function &&other)
{
if (this != &other)
{
delete _ptr;
_ptr = other._ptr;
other._ptr = nullptr;
}
return *this;
}
function &operator=(std::nullptr_t) noexcept
{
delete _ptr;
_ptr = nullptr;
return *this;
}
template <class F>
function &operator=(F &&f)
{
delete _ptr;
_ptr = new impl<F>(std::forward<F>(f));
return *this;
}
template <class F>
function &operator=(std::reference_wrapper<F> f) noexcept
{
delete _ptr;
_ptr = new impl<std::reference_wrapper<F>>(f);
return *this;
}
void swap(function &other) noexcept
{
std::swap(_ptr, other._ptr);
}
explicit operator bool() const noexcept
{
return _ptr != nullptr;
}
R operator()(Args... args) const
{
return _ptr->invoke(std::forward<Args>(args)...);
}
#ifdef __GXX_RTTI
const std::type_info &target_type() const noexcept
{
return _ptr ? _ptr->target_type() : typeid(void);
}
template <class T>
T *target() noexcept
{
return _ptr && _ptr->target_type() == typeid(T) ? &static_cast<impl<T> *>(_ptr)->_f : nullptr;
}
template <class T>
const T *target() const noexcept
{
return _ptr && _ptr->target_type() == typeid(T) ? &static_cast<impl<T> *>(_ptr)->_f : nullptr;
}
#endif
};
template <class R, class... Args>
void swap(std::function<R(Args...)> &lhs, std::function<R(Args...)> &rhs) noexcept
{
lhs.swap(rhs);
}
template <class R, class... ArgTypes>
bool operator==(const std::function<R(ArgTypes...)> &f, std::nullptr_t) noexcept
{
return !f;
}
template <class T = void>
struct less
{
constexpr bool operator()(const T &lhs, const T &rhs) const
{
return lhs < rhs;
}
};
}

View File

@ -21,28 +21,41 @@
namespace std
{
template <typename T>
template <typename _E>
class initializer_list
{
public:
typedef _E value_type;
typedef const _E &reference;
typedef const _E &const_reference;
typedef size_t size_type;
typedef const _E *iterator;
typedef const _E *const_iterator;
private:
const T *array;
size_t len;
iterator array;
size_type len;
public:
initializer_list() : array(nullptr), len(0) {}
size_t size() const { return len; }
const T *begin() const { return array; }
const T *end() const { return begin() + size(); }
constexpr initializer_list(const_iterator a, size_type l)
: array(a), len(l) {}
constexpr initializer_list()
: array(nullptr), len(0) {}
constexpr size_type size() const { return len; }
constexpr const_iterator begin() const { return array; }
constexpr const_iterator end() const { return begin() + size(); }
};
template <class E>
const E *begin(std::initializer_list<E> il)
constexpr const E *begin(initializer_list<E> il)
{
return il.begin();
}
template <class E>
constexpr const E *end(std::initializer_list<E> il)
constexpr const E *end(initializer_list<E> il)
{
return il.end();
}

23
include_std/inttypes.h Normal file
View File

@ -0,0 +1,23 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __FENNIX_KERNEL_INTTYPES_H__
#define __FENNIX_KERNEL_INTTYPES_H__
#include <types.h>
#endif // !__FENNIX_KERNEL_INTTYPES_H__

286
include_std/ios Normal file
View File

@ -0,0 +1,286 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <system_error>
#include <string>
#include <vector>
#include <locale>
#ifdef in
#undef in
#endif /* deprecated macro in */
namespace std
{
enum class io_errc
{
stream = 1,
};
typedef long long streamsize;
class ios_base
{
public:
#pragma region Member types and constants
typedef int openmode;
static constexpr openmode app = 1;
static constexpr openmode binary = 2;
static constexpr openmode in = 4;
static constexpr openmode out = 8;
static constexpr openmode trunc = 16;
static constexpr openmode ate = 32;
static constexpr openmode noreplace = 64;
typedef int fmtflags;
static constexpr fmtflags dec = 1;
static constexpr fmtflags oct = 2;
static constexpr fmtflags hex = 4;
static constexpr fmtflags basefield = dec | oct | hex;
static constexpr fmtflags left = 1;
static constexpr fmtflags right = 2;
static constexpr fmtflags internal = 4;
static constexpr fmtflags adjustfield = left | right | internal;
static constexpr fmtflags scientific = 1;
static constexpr fmtflags fixed = 2;
static constexpr fmtflags floatfield = scientific | fixed;
static constexpr fmtflags boolalpha = 1;
static constexpr fmtflags showbase = 2;
static constexpr fmtflags showpoint = 4;
static constexpr fmtflags showpos = 8;
static constexpr fmtflags skipws = 16;
static constexpr fmtflags unitbuf = 32;
static constexpr fmtflags uppercase = 64;
typedef int iostate;
static constexpr iostate goodbit = 0;
static constexpr iostate badbit = 1;
static constexpr iostate failbit = 2;
static constexpr iostate eofbit = 4;
typedef int seekdir;
static constexpr seekdir beg = 0;
static constexpr seekdir end = 1;
static constexpr seekdir cur = 2;
enum event
{
erase_event,
imbue_event,
copyfmt_event
};
typedef void (*event_callback)(event type, ios_base &ios, int index);
#pragma endregion Member types and constants
#pragma region Member Functions
protected:
ios_base();
public:
ios_base(const ios_base &) = delete;
virtual ~ios_base() = default;
ios_base &operator=(const ios_base &) = delete;
#pragma endregion Member Functions
#pragma region Formatting
fmtflags flags() const
{
return _flags;
}
fmtflags flags(fmtflags flags)
{
fmtflags old = _flags;
_flags = flags;
return old;
}
fmtflags setf(fmtflags flags)
{
fmtflags old = _flags;
_flags |= flags;
return old;
}
fmtflags setf(fmtflags flags, fmtflags mask)
{
fmtflags old = _flags;
_flags &= ~mask;
_flags |= flags;
return old;
}
void unsetf(fmtflags flags)
{
_flags &= ~flags;
}
streamsize precision() const
{
return _precision;
}
streamsize precision(streamsize new_precision)
{
streamsize old = _precision;
_precision = new_precision;
return old;
}
streamsize width() const
{
return _width;
}
streamsize width(streamsize new_width)
{
streamsize old = _width;
_width = new_width;
return old;
}
#pragma endregion Formatting
#pragma region Locales
std::locale imbue(const std::locale &loc)
{
std::locale old = _loc;
_loc = loc;
__call_event(imbue_event, *this, 0);
return old;
}
std::locale getloc() const
{
return _loc;
}
#pragma endregion Locales
#pragma region Internal Extensible Array
static int xalloc()
{
static int index = 0;
return index++;
}
long &iword(int index)
{
static std::vector<long> iwords;
if ((size_t)index >= iwords.size())
iwords.resize(index + 1);
return iwords[index];
}
void *&pword(int index)
{
static std::vector<void *> pwords;
if ((size_t)index >= pwords.size())
pwords.resize(index + 1);
return pwords[index];
}
#pragma endregion Internal Extensible Array
#pragma region Miscellaneous
void register_callback(event_callback function, int index)
{
_event_callback = function;
__call_event(imbue_event, *this, index);
}
static bool sync_with_stdio(bool sync = true)
{
return false;
}
#pragma endregion Miscellaneous
#pragma region Member Classes
class failure
{
public:
explicit failure(const std::string &message, const std::error_code &ec = std::io_errc::stream)
{
}
explicit failure(const char *message, const std::error_code &ec = std::io_errc::stream)
{
}
failure(const failure &other) noexcept
{
}
failure &operator=(const failure &other) noexcept
{
return *this;
}
virtual const char *what() const noexcept
{
return nullptr;
}
};
class Init
{
public:
Init() = default;
~Init() = default;
};
#pragma endregion Member Classes
private:
fmtflags _flags = skipws;
streamsize _precision = 6;
streamsize _width = 0;
std::locale _loc = std::locale::classic();
static event_callback _event_callback;
static void __call_event(event type, ios_base &ios, int index)
{
if (_event_callback)
_event_callback(type, ios, index);
}
};
template <class CharT, class Traits = std::char_traits<CharT>>
class basic_ios : public std::ios_base
{
};
typedef basic_ios<char> ios;
typedef basic_ios<wchar_t> wios;
}

36
include_std/iostream Normal file
View File

@ -0,0 +1,36 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <ostream>
#include <istream>
namespace std
{
extern std::istream cin;
extern std::wistream wcin;
extern std::ostream cout;
extern std::wostream wcout;
extern std::ostream cerr;
extern std::wostream wcerr;
extern std::ostream clog;
extern std::wostream wclog;
}

79
include_std/istream Normal file
View File

@ -0,0 +1,79 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <streambuf>
#include <ostream>
#include <string>
#include <ios>
namespace std
{
template <class CharT, class Traits = std::char_traits<CharT>>
class basic_istream : virtual public std::basic_ios<CharT, Traits>
{
};
template <class CharT, class Traits = std::char_traits<CharT>>
class basic_iostream : public basic_istream<CharT, Traits>, public basic_ostream<CharT, Traits>
{
private:
void init(std::basic_streambuf<CharT, Traits> *sb)
{
this->basic_istream<CharT, Traits>::rdbuf(sb);
this->basic_ostream<CharT, Traits>::rdbuf(sb);
}
public:
typedef CharT char_type;
typedef Traits::char_type traits_type;
typedef Traits::int_type int_type;
typedef Traits::pos_type pos_type;
typedef Traits::off_type off_type;
explicit basic_iostream(std::basic_streambuf<CharT, Traits> *sb)
{
this->init(sb);
}
basic_iostream(const basic_iostream &other) = delete;
virtual ~basic_iostream() = default;
basic_iostream &operator=(const basic_iostream &other) = delete;
protected:
basic_iostream(basic_iostream &&other)
{
this->rdbuf(other.rdbuf());
other.rdbuf(nullptr);
}
basic_iostream &operator=(basic_iostream &&other);
void swap(basic_iostream &other)
{
std::swap(this->rdbuf(), other.rdbuf());
}
};
typedef basic_istream<char> istream;
typedef basic_istream<wchar_t> wistream;
typedef basic_iostream<char> iostream;
typedef basic_iostream<wchar_t> wiostream;
}

View File

@ -43,26 +43,21 @@ namespace std
{
};
template <class Iter>
class reverse_iterator
{
public:
/* FIXME: missing implementation */
};
template <class Iter>
struct iterator_traits
{
public:
typedef Iter::difference_type difference_type;
/* FIXME: missing implementation */
using difference_type = typename Iter::difference_type;
using value_type = typename Iter::value_type;
using pointer = typename Iter::pointer;
using reference = typename Iter::reference;
using iterator_category = typename Iter::iterator_category;
};
template <class It>
constexpr typename std::iterator_traits<It>::difference_type __do_distance(It first, It last, std::input_iterator_tag)
template <class InputIt>
constexpr typename std::iterator_traits<InputIt>::difference_type __do_distance(InputIt first, InputIt last, std::input_iterator_tag)
{
typename std::iterator_traits<It>::difference_type result = 0;
typename std::iterator_traits<InputIt>::difference_type result = 0;
while (first != last)
{
++first;
@ -71,8 +66,8 @@ namespace std
return result;
}
template <class It>
constexpr typename std::iterator_traits<It>::difference_type __do_distance(It first, It last, std::random_access_iterator_tag)
template <class InputIt>
constexpr typename std::iterator_traits<InputIt>::difference_type __do_distance(InputIt first, InputIt last, std::random_access_iterator_tag)
{
return last - first;
}
@ -82,4 +77,56 @@ namespace std
{
return __do_distance(first, last, typename std::iterator_traits<InputIt>::iterator_category());
}
template <class InputIt>
void __do_advance(InputIt &it, typename std::iterator_traits<InputIt>::difference_type n, std::input_iterator_tag)
{
while (n > 0)
{
--n;
++it;
}
}
template <class InputIt>
void __do_advance(InputIt &it, typename std::iterator_traits<InputIt>::difference_type n, std::bidirectional_iterator_tag)
{
while (n > 0)
{
--n;
++it;
}
while (n < 0)
{
++n;
--it;
}
}
template <class InputIt>
void __do_advance(InputIt &it, typename std::iterator_traits<InputIt>::difference_type n, std::random_access_iterator_tag)
{
it += n;
}
template <class InputIt, class Distance>
constexpr void advance(InputIt &it, Distance n)
{
__do_advance(it, typename std::iterator_traits<InputIt>::difference_type(n),
typename std::iterator_traits<InputIt>::iterator_category());
}
template <class BidirIt>
constexpr BidirIt prev(BidirIt it, typename std::iterator_traits<BidirIt>::difference_type n = 1)
{
std::advance(it, -n);
return it;
}
template <class InputIt>
constexpr InputIt next(InputIt it, typename std::iterator_traits<InputIt>::difference_type n = 1)
{
std::advance(it, n);
return it;
}
}

File diff suppressed because it is too large Load Diff

159
include_std/locale Normal file
View File

@ -0,0 +1,159 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <cstddef>
#include <cassert>
#include <string>
namespace std
{
class locale
{
public:
#pragma region Member Types
class id
{
public:
id() = default;
id(const id &) = delete;
};
class facet
{
private:
std::size_t refs;
public:
explicit facet(std::size_t refs = 0)
{
this->refs = refs;
}
facet(const facet &) = delete;
protected:
virtual ~facet() = default;
};
typedef int category;
#pragma endregion Member Types
#pragma region Member Objects
static const category none = 0;
static const category collate = 1;
static const category ctype = 2;
static const category monetary = 4;
static const category numeric = 8;
static const category time = 16;
static const category messages = 32;
static const category all = collate | ctype | monetary | numeric | time | messages;
#pragma endregion Member Objects
#pragma region Member Functions
locale() noexcept
{
assert(!"Function not implemented");
}
locale(const locale &other) noexcept
{
assert(!"Function not implemented");
}
explicit locale(const char *std_name)
{
assert(!"Function not implemented");
}
explicit locale(const std::string &std_name)
{
assert(!"Function not implemented");
}
locale(const locale &other, const char *std_name, category cats)
{
assert(!"Function not implemented");
}
locale(const locale &other, const std::string &std_name, category cats)
{
assert(!"Function not implemented");
}
template <class Facet>
locale(const locale &other, Facet *f)
{
assert(!"Function not implemented");
}
locale(const locale &other, const locale &one, category cats)
{
assert(!"Function not implemented");
}
~locale()
{
assert(!"Function not implemented");
}
const locale &operator=(const locale &other) noexcept
{
assert(!"Function not implemented");
}
template <class Facet>
locale combine(const locale &other) const
{
assert(!"Function not implemented");
}
std::string name() const
{
assert(!"Function not implemented");
}
bool operator==(const locale &other) const
{
assert(!"Function not implemented");
}
template <class CharT, class Traits, class Alloc>
bool operator()(const basic_string<CharT, Traits, Alloc> &s1, const basic_string<CharT, Traits, Alloc> &s2) const
{
assert(!"Function not implemented");
}
static locale global(const locale &loc)
{
assert(!"Function not implemented");
}
static const locale &classic()
{
assert(!"Function not implemented");
}
#pragma endregion Member Functions
};
}

View File

@ -18,12 +18,136 @@
#pragma once
#include <type_traits>
#include <functional>
#include <cstddef>
#include <utility>
#include <limits>
#include <new>
#include <debug.h>
namespace std
{
namespace __memory__detail
{
template <class>
constexpr bool is_unbounded_array_v = false;
template <class T>
constexpr bool is_unbounded_array_v<T[]> = true;
template <class>
constexpr bool is_bounded_array_v = false;
template <class T, std::size_t N>
constexpr bool is_bounded_array_v<T[N]> = true;
}
template <class T, class... Args>
constexpr T *construct_at(T *p, Args &&...args)
{
return ::new (static_cast<void *>(p)) T(std::forward<Args>(args)...);
}
template <class T>
constexpr void destroy_at(T *p)
{
p->~T();
}
template <class T>
T *addressof(T &arg)
{
return reinterpret_cast<T *>(&const_cast<char &>(reinterpret_cast<const volatile char &>(arg)));
}
template <class T>
const T *addressof(const T &&) = delete;
template <class InputIt, class Size, class NoThrowForwardIt>
NoThrowForwardIt uninitialized_copy_n(InputIt first, Size count, NoThrowForwardIt d_first)
{
using ValueType = typename std::iterator_traits<NoThrowForwardIt>::value_type;
NoThrowForwardIt current = d_first;
try
{
for (Size i = 0; i < count; ++i, (void)++current, ++first)
{
::new (static_cast<void *>(std::addressof(*current))) ValueType(*first);
}
return current;
}
catch (...)
{
for (; d_first != current; ++d_first)
{
d_first->~ValueType();
}
throw;
}
}
template <class ExecutionPolicy, class ForwardIt, class Size, class NoThrowForwardIt>
NoThrowForwardIt uninitialized_copy_n(ExecutionPolicy &&policy, ForwardIt first, Size count, NoThrowForwardIt d_first)
{
return uninitialized_copy_n(first, count, d_first);
}
template <class ForwardIt, class Size, class T>
ForwardIt uninitialized_fill_n(ForwardIt first, Size count, const T &value)
{
using V = typename std::iterator_traits<ForwardIt>::value_type;
ForwardIt current = first;
try
{
for (; count > 0; ++current, (void)--count)
::new (static_cast<void *>(std::addressof(*current))) V(value);
return current;
}
catch (...)
{
for (; first != current; ++first)
first->~V();
throw;
}
}
template <class ExecutionPolicy, class ForwardIt, class Size, class T>
ForwardIt uninitialized_fill_n(ExecutionPolicy &&policy, ForwardIt first, Size count, const T &value)
{
return uninitialized_fill_n(first, count, value);
}
template <class Ptr>
struct pointer_traits
{
using pointer = Ptr;
using element_type = typename Ptr::element_type;
using difference_type = typename Ptr::difference_type;
template <class U>
using rebind = typename Ptr::template rebind<U>;
static pointer pointer_to(element_type &r) noexcept
{
return Ptr::pointer_to(r);
}
};
template <class T>
struct pointer_traits<T *>
{
using pointer = T *;
using element_type = T;
using difference_type = std::ptrdiff_t;
template <class U>
using rebind = U *;
static pointer pointer_to(element_type &r) noexcept
{
return std::addressof(r);
}
};
template <class Pointer, class SizeType = std::size_t>
struct allocation_result
{
@ -31,6 +155,73 @@ namespace std
SizeType count;
};
template <class Alloc>
struct allocator_traits
{
typedef Alloc allocator_type;
typedef typename Alloc::value_type value_type;
typedef typename Alloc::pointer pointer;
typedef typename Alloc::const_pointer const_pointer;
// typedef typename Alloc::void_pointer void_pointer;
// typedef typename Alloc::const_void_pointer const_void_pointer;
// typedef typename std::pointer_traits<pointer>::rebind<void> void_pointer;
// typedef typename std::pointer_traits<pointer>::rebind<const void> const_void_pointer;
typedef typename Alloc::difference_type difference_type;
typedef typename Alloc::size_type size_type;
// typedef typename Alloc::propagate_on_container_copy_assignment propagate_on_container_copy_assignment;
typedef typename std::false_type propagate_on_container_copy_assignment;
typedef typename Alloc::propagate_on_container_move_assignment propagate_on_container_move_assignment;
typedef typename std::false_type propagate_on_container_swap;
typedef typename Alloc::is_always_equal is_always_equal;
template <class T>
using rebind_alloc = typename Alloc::template rebind<T>::other;
template <class T>
using rebind_traits = allocator_traits<rebind_alloc<T>>;
[[nodiscard]] static constexpr pointer allocate(Alloc &a, size_type n)
{
return a.allocate(n);
}
// [[nodiscard]] static constexpr pointer allocate(Alloc &a, size_type n, const_void_pointer hint)
// {
// return a.allocate(n, hint);
// }
[[nodiscard]] static constexpr std::allocation_result<pointer, size_type> allocate_at_least(Alloc &a, size_type n)
{
return a.allocate_at_least(n);
}
static constexpr void deallocate(Alloc &a, pointer p, size_type n)
{
a.deallocate(p, n);
}
template <class T, class... Args>
static constexpr void construct(Alloc &a, T *p, Args &&...args)
{
std::construct_at(p, std::forward<Args>(args)...);
}
template <class T>
static constexpr void destroy(Alloc &a, T *p)
{
std::destroy_at(p);
}
static constexpr size_type max_size(const Alloc &a)
{
return a.max_size();
}
static constexpr Alloc select_on_container_copy_construction(const Alloc &a)
{
return a;
}
};
template <class T>
struct allocator
{
@ -64,9 +255,7 @@ namespace std
std::allocation_result<T *, std::size_t> allocate_at_least(std::size_t n)
{
if (n > max_size())
return {nullptr, 0};
return {allocate(n), n};
return {static_cast<T *>(::operator new(n * sizeof(T))), n};
}
void deallocate(T *p, std::size_t n)
@ -74,35 +263,344 @@ namespace std
::operator delete(p);
}
size_type max_size() const
{
return std::numeric_limits<size_type>::max() / sizeof(T);
}
void construct(pointer p, const_reference val)
{
::new ((void *)p) T(val);
}
template <class U, class... Args>
void construct(U *p, Args &&...args)
{
::new ((void *)p) U(std::forward<Args>(args)...);
}
void destroy(pointer p) { p->~T(); }
template <class U>
void destroy(U *p) { p->~U(); }
pointer address(reference x) const { return &x; }
const_pointer address(const_reference x) const { return &x; }
};
template <class T>
T *addressof(T &arg)
struct default_delete
{
return reinterpret_cast<T *>(&const_cast<char &>(reinterpret_cast<const volatile char &>(arg)));
constexpr default_delete() noexcept = default;
template <class U>
constexpr default_delete(const default_delete<U> &d) noexcept {}
constexpr void operator()(T *ptr) const { delete ptr; }
};
template <class T>
struct default_delete<T[]>
{
constexpr default_delete() noexcept = default;
template <class U>
constexpr default_delete(const default_delete<U[]> &d) noexcept {}
template <class U>
constexpr void operator()(U *ptr) const { delete[] ptr; }
};
template <class T, class Deleter = std::default_delete<T>>
class unique_ptr
{
public:
using pointer = T *; // std::remove_reference<Deleter>::type::pointer;
using element_type = T;
using deleter_type = Deleter;
private:
pointer _ptr;
public:
#pragma region Member Functions
constexpr unique_ptr() noexcept : _ptr(nullptr) {}
constexpr unique_ptr(std::nullptr_t) noexcept : _ptr(nullptr) {}
constexpr explicit unique_ptr(pointer p) noexcept : _ptr(p) {}
// constexpr unique_ptr(pointer p, /* TODO */ d1) noexcept : _ptr(p) {}
// constexpr unique_ptr(pointer p, /* TODO */ d2) noexcept : _ptr(p) {}
constexpr unique_ptr(unique_ptr &&u) noexcept : _ptr(u.release()) {}
template <class U, class E>
constexpr unique_ptr(unique_ptr<U, E> &&u) noexcept : _ptr(u.release()) {}
unique_ptr(const unique_ptr &) = delete;
~unique_ptr()
{
if (_ptr == nullptr)
return;
Deleter d;
d(_ptr);
}
constexpr unique_ptr &operator=(unique_ptr &&r) noexcept
{
reset(r.release());
return *this;
}
template <class U, class E>
constexpr unique_ptr &operator=(unique_ptr<U, E> &&r) noexcept
{
reset(r.release());
return *this;
}
constexpr unique_ptr &operator=(std::nullptr_t) noexcept
{
reset();
return *this;
}
unique_ptr &operator=(const unique_ptr &) = delete;
#pragma endregion Member Functions
#pragma region Modifiers
constexpr pointer release() noexcept
{
pointer p = _ptr;
_ptr = nullptr;
return p;
}
constexpr void reset(pointer ptr = pointer()) noexcept
{
Deleter d;
d(_ptr);
_ptr = ptr;
}
void swap(unique_ptr &other) noexcept
{
pointer tmp = _ptr;
_ptr = other._ptr;
other._ptr = tmp;
}
#pragma endregion Modifiers
#pragma region Observers
constexpr pointer get() const noexcept { return _ptr; }
constexpr Deleter &get_deleter() noexcept { return _ptr; }
constexpr const Deleter &get_deleter() const noexcept { return _ptr; }
constexpr explicit operator bool() const noexcept { return get() != nullptr; }
#pragma endregion Observers
#pragma region Element Access
constexpr typename std::add_lvalue_reference<T>::type operator*() const noexcept(noexcept(*std::declval<pointer>())) { return *_ptr; }
constexpr pointer operator->() const noexcept { return _ptr; }
#pragma endregion Element Access
};
template <class T, class Deleter>
class unique_ptr<T[], Deleter>
{
public:
using pointer = T *; // std::remove_reference<Deleter>::type::pointer;
using element_type = T;
using deleter_type = Deleter;
private:
pointer _ptr;
public:
#pragma region Member Functions
constexpr unique_ptr() noexcept : _ptr(nullptr) {}
constexpr unique_ptr(std::nullptr_t) noexcept : _ptr(nullptr) {}
template <class U>
constexpr explicit unique_ptr(U p) noexcept : _ptr(p) {}
// template <class U>
// constexpr unique_ptr(U p, /* TODO */ d1) noexcept : _ptr(p) {}
// template <class U>
// constexpr unique_ptr(U p, /* TODO */ d2) noexcept : _ptr(p) {}
constexpr unique_ptr(unique_ptr &&u) noexcept : _ptr(u.release()) {}
template <class U, class E>
constexpr unique_ptr(unique_ptr<U, E> &&u) noexcept : _ptr(u.release()) {}
unique_ptr(const unique_ptr &) = delete;
~unique_ptr()
{
if (_ptr == nullptr)
return;
Deleter d;
d(_ptr);
}
constexpr unique_ptr &operator=(unique_ptr &&r) noexcept
{
reset(r.release());
return *this;
}
template <class U, class E>
constexpr unique_ptr &operator=(unique_ptr<U, E> &&r) noexcept
{
reset(r.release());
return *this;
}
constexpr unique_ptr &operator=(std::nullptr_t) noexcept
{
reset();
return *this;
}
unique_ptr &operator=(const unique_ptr &) = delete;
#pragma endregion Member Functions
#pragma region Modifiers
constexpr pointer release() noexcept
{
pointer p = _ptr;
_ptr = nullptr;
return p;
}
template <class U>
constexpr void reset(U ptr) noexcept
{
Deleter d;
d(_ptr);
_ptr = ptr;
}
constexpr void reset(std::nullptr_t = nullptr) noexcept
{
Deleter d;
d(_ptr);
_ptr = nullptr;
}
void swap(unique_ptr &other) noexcept
{
pointer tmp = _ptr;
_ptr = other._ptr;
other._ptr = tmp;
}
#pragma endregion Modifiers
#pragma region Observers
constexpr pointer get() const noexcept { return _ptr; }
constexpr Deleter &get_deleter() noexcept { return _ptr; }
constexpr const Deleter &get_deleter() const noexcept { return _ptr; }
constexpr explicit operator bool() const noexcept { return get() != nullptr; }
#pragma endregion Observers
#pragma region Element Access
constexpr T &operator[](std::size_t i) const { return _ptr[i]; }
#pragma endregion Element Access
};
template <class T, class... Args>
std::enable_if_t<!std::is_array<T>::value, std::unique_ptr<T>>
make_unique(Args &&...args)
{
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
template <class T>
const T *addressof(const T &&) = delete;
std::enable_if_t<__memory__detail::is_unbounded_array_v<T>, std::unique_ptr<T>>
make_unique(std::size_t n)
{
return std::unique_ptr<T>(new std::remove_extent_t<T>[n]());
}
template <class T, class... Args>
std::enable_if_t<__memory__detail::is_bounded_array_v<T>> make_unique(Args &&...) = delete;
template <class T>
requires(!std::is_array_v<T>)
std::unique_ptr<T> make_unique_for_overwrite()
{
return std::unique_ptr<T>(new T);
}
template <class T>
requires std::is_unbounded_array_v<T>
std::unique_ptr<T> make_unique_for_overwrite(std::size_t n)
{
return std::unique_ptr<T>(new std::remove_extent_t<T>[n]);
}
template <class T, class... Args>
requires std::is_bounded_array_v<T>
void make_unique_for_overwrite(Args &&...) = delete;
template <class T1, class D1, class T2, class D2>
constexpr bool operator==(const unique_ptr<T1, D1> &x, const unique_ptr<T2, D2> &y) { return x.get() == y.get(); }
template <class T1, class D1, class T2, class D2>
bool operator<(const unique_ptr<T1, D1> &x, const unique_ptr<T2, D2> &y)
{
return std::less<typename std::common_type<typename unique_ptr<T1, D1>::pointer, typename unique_ptr<T2, D2>::pointer>::type>()(x.get(), y.get());
}
template <class T1, class D1, class T2, class D2>
bool operator<=(const unique_ptr<T1, D1> &x, const unique_ptr<T2, D2> &y) { return !(y < x); }
template <class T1, class D1, class T2, class D2>
bool operator>(const unique_ptr<T1, D1> &x, const unique_ptr<T2, D2> &y) { return y < x; }
template <class T1, class D1, class T2, class D2>
bool operator>=(const unique_ptr<T1, D1> &x, const unique_ptr<T2, D2> &y) { return !(x < y); }
// operator<=>(const unique_ptr<T1, D1> &x, const unique_ptr<T2, D2> &y);
template <class T, class D>
constexpr bool operator==(const unique_ptr<T, D> &x, std::nullptr_t) noexcept { return !x; }
template <class T, class D>
constexpr bool operator<(const unique_ptr<T, D> &x, std::nullptr_t) { return std::less<typename unique_ptr<T, D>::pointer>()(x.get(), nullptr); }
template <class T, class D>
constexpr bool operator<(std::nullptr_t, const unique_ptr<T, D> &y) { return std::less<typename unique_ptr<T, D>::pointer>()(nullptr, y.get()); }
template <class T, class D>
constexpr bool operator<=(const unique_ptr<T, D> &x, std::nullptr_t) { return !(nullptr < x); }
template <class T, class D>
constexpr bool operator<=(std::nullptr_t, const unique_ptr<T, D> &y) { return !(y < nullptr); }
template <class T, class D>
constexpr bool operator>(const unique_ptr<T, D> &x, std::nullptr_t) { return nullptr < x; }
template <class T, class D>
constexpr bool operator>(std::nullptr_t, const unique_ptr<T, D> &y) { return y < nullptr; }
template <class T, class D>
constexpr bool operator>=(const unique_ptr<T, D> &x, std::nullptr_t) { return !(x < nullptr); }
template <class T, class D>
constexpr bool operator>=(std::nullptr_t, const unique_ptr<T, D> &y) { return !(nullptr < y); }
// operator<=>(const unique_ptr<T, D> &x, std::nullptr_t);
// template <class CharT, class Traits, class Y, class D>
// std::basic_ostream<CharT, Traits> &operator<<(std::basic_ostream<CharT, Traits> &os, const std::unique_ptr<Y, D> &p)
// {
// return os << p.get();
// }
template <class T, class D>
void swap(std::unique_ptr<T, D> &lhs, std::unique_ptr<T, D> &rhs) noexcept
{
lhs.swap(rhs);
}
}

23
include_std/memory.h Normal file
View File

@ -0,0 +1,23 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __FENNIX_KERNEL_STD_MEMORY_H__
#define __FENNIX_KERNEL_STD_MEMORY_H__
#include <convert.h>
#endif // !__FENNIX_KERNEL_STD_MEMORY_H__

143
include_std/new Normal file
View File

@ -0,0 +1,143 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <cstddef>
#include <exception>
namespace std
{
enum class align_val_t : std::size_t
{
};
struct nothrow_t
{
explicit nothrow_t() = default;
};
extern const std::nothrow_t nothrow;
struct destroying_delete_t
{
explicit destroying_delete_t() = default;
};
inline constexpr destroying_delete_t destroying_delete{};
typedef void (*new_handler)();
std::new_handler set_new_handler(std::new_handler new_p) noexcept;
std::new_handler get_new_handler() noexcept;
class bad_alloc : public exception
{
public:
bad_alloc() noexcept = default;
bad_alloc(const bad_alloc &other) noexcept = default;
bad_alloc &operator=(const bad_alloc &other) noexcept = default;
virtual const char *what() const noexcept
{
return "bad_alloc";
}
};
class bad_array_new_length : public bad_alloc
{
public:
bad_array_new_length() noexcept = default;
bad_array_new_length(const bad_array_new_length &other) noexcept = default;
virtual ~bad_array_new_length() = default;
bad_array_new_length &operator=(const bad_array_new_length &other) noexcept
{
return *this;
}
virtual const char *what() const noexcept
{
return "bad_array_new_length";
}
};
}
[[nodiscard]] void *operator new(std::size_t count);
[[nodiscard]] void *operator new[](std::size_t count);
// [[nodiscard]] void *operator new(std::size_t count, std::align_val_t al);
// [[nodiscard]] void *operator new[](std::size_t count, std::align_val_t al);
// [[nodiscard]] void *operator new(std::size_t count, const std::nothrow_t &tag) noexcept;
// [[nodiscard]] void *operator new[](std::size_t count, const std::nothrow_t &tag) noexcept;
// [[nodiscard]] void *operator new(std::size_t count, std::align_val_t al, const std::nothrow_t &) noexcept;
// [[nodiscard]] void *operator new[](std::size_t count, std::align_val_t al, const std::nothrow_t &) noexcept;
[[nodiscard]] void *operator new(std::size_t count, void *ptr) noexcept;
[[nodiscard]] void *operator new[](std::size_t count, void *ptr) noexcept;
// void *operator new(std::size_t count, ...);
// void *operator new[](std::size_t count, ...);
// void *operator new(std::size_t count, std::align_val_t al, ...);
// void *operator new[](std::size_t count, std::align_val_t al, ...);
// void *T::operator new(std::size_t count);
// void *T::operator new[](std::size_t count);
// void *T::operator new(std::size_t count, std::align_val_t al);
// void *T::operator new[](std::size_t count, std::align_val_t al);
// void *T::operator new(std::size_t count, ...);
// void *T::operator new[](std::size_t count, ...);
// void *T::operator new(std::size_t count, std::align_val_t al, ...);
// void *T::operator new[](std::size_t count, std::align_val_t al, ...);
void operator delete(void *ptr) noexcept;
void operator delete[](void *ptr) noexcept;
// void operator delete(void *ptr, std::align_val_t al) noexcept;
// void operator delete[](void *ptr, std::align_val_t al) noexcept;
void operator delete(void *ptr, std::size_t sz) noexcept;
// void operator delete[](void *ptr, std::size_t sz) noexcept;
// void operator delete(void *ptr, std::size_t sz, std::align_val_t al) noexcept;
// void operator delete[](void *ptr, std::size_t sz, std::align_val_t al) noexcept;
// void operator delete(void *ptr, const std::nothrow_t &tag) noexcept;
// void operator delete[](void *ptr, const std::nothrow_t &tag) noexcept;
// void operator delete(void *ptr, std::align_val_t al, const std::nothrow_t &tag) noexcept;
// void operator delete[](void *ptr, std::align_val_t al, const std::nothrow_t &tag) noexcept;
// void operator delete(void *ptr, void *place) noexcept;
// void operator delete[](void *ptr, void *place) noexcept;
// void operator delete(void *ptr, ...);
// void operator delete[](void *ptr, ...);
// void T::operator delete(void *ptr);
// void T::operator delete[](void *ptr);
// void T::operator delete(void *ptr, std::align_val_t al);
// void T::operator delete[](void *ptr, std::align_val_t al);
// void T::operator delete(void *ptr, std::size_t sz);
// void T::operator delete[](void *ptr, std::size_t sz);
// void T::operator delete(void *ptr, std::size_t sz, std::align_val_t al);
// void T::operator delete[](void *ptr, std::size_t sz, std::align_val_t al);
// void T::operator delete(void *ptr, args...);
// void T::operator delete[](void *ptr, args...);
// void T::operator delete(T *ptr, std::destroying_delete_t);
// void T::operator delete(T *ptr, std::destroying_delete_t, std::align_val_t al);
// void T::operator delete(T *ptr, std::destroying_delete_t, std::size_t sz);
// void T::operator delete(T *ptr, std::destroying_delete_t, std::size_t sz, std::align_val_t al);

40
include_std/ostream Normal file
View File

@ -0,0 +1,40 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <string>
#include <ios>
namespace std
{
template <class CharT, class Traits = std::char_traits<CharT>>
class basic_ostream : virtual public std::basic_ios<CharT, Traits>
{
};
template <class CharT, class Traits>
std::basic_ostream<CharT, Traits> &endl(std::basic_ostream<CharT, Traits> &os)
{
os.put(os.widen('\n'));
os.flush();
return os;
}
typedef basic_ostream<char> ostream;
typedef basic_ostream<wchar_t> wostream;
}

23
include_std/signal.h Normal file
View File

@ -0,0 +1,23 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __FENNIX_KERNEL_STD_SIGNAL_H__
#define __FENNIX_KERNEL_STD_SIGNAL_H__
#include <types.h>
#endif // !__FENNIX_KERNEL_STD_SIGNAL_H__

View File

@ -1,68 +0,0 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
/* This function includes all the standard headers and defines some useful macros.
* Note: This std implementation is not complete.
*/
#ifndef __FENNIX_KERNEL_STD_H__
#define __FENNIX_KERNEL_STD_H__
#include <types.h>
/**
* @brief // stub namespace for std::align_val_t and new operator
* @note // Found on https://gcc.gnu.org/legacy-ml/gcc-patches/2016-09/msg00628.html for "_ZnwmSt11align_val_t" compiler error
*/
namespace std
{
typedef __SIZE_TYPE__ size_t;
static const size_t npos = -1;
enum class align_val_t : std::size_t
{
};
template <typename InputIt, typename OutputIt, typename UnaryOperation>
OutputIt transform(InputIt first, InputIt last, OutputIt result, UnaryOperation op)
{
while (first != last)
{
*result = op(*first);
++first;
++result;
}
return result;
};
inline __always_inline int tolower(int c)
{
if (c >= 'A' && c <= 'Z')
return c + ('a' - 'A');
else
return c;
}
inline __always_inline int toupper(int c)
{
if (c >= 'a' && c <= 'z')
return c - ('a' - 'A');
else
return c;
}
}
#endif // !__FENNIX_KERNEL_STD_H__

View File

@ -1,266 +0,0 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __FENNIX_KERNEL_STD_SMART_POINTER_H__
#define __FENNIX_KERNEL_STD_SMART_POINTER_H__
#include <types.h>
#include <type_traits>
#include <debug.h>
// show debug messages
// #define DEBUG_SMARTPOINTERS 1
#ifdef DEBUG_SMARTPOINTERS
#define spdbg(m, ...) debug(m, ##__VA_ARGS__)
#else
#define spdbg(m, ...)
#endif
namespace std
{
/**
* @brief A smart pointer class
*
* This class is a smart pointer class. It is used to manage the lifetime of
* objects. It is a reference counted pointer, so when the last reference to
* the object is removed, the object is deleted.
*
* Basic Usage:
* smart_ptr<char> pointer(new char());
* *pointer = 'a';
* printf("%c", *pointer); // Prints "a"
*/
template <class T>
class smart_ptr
{
T *RealPointer;
public:
explicit smart_ptr(T *Pointer = nullptr)
{
spdbg("Smart pointer created (%#lx)", this->RealPointer);
this->RealPointer = Pointer;
}
~smart_ptr()
{
spdbg("Smart pointer deleted (%#lx)", this->RealPointer);
delete this->RealPointer, this->RealPointer = nullptr;
}
T &operator*()
{
spdbg("Smart pointer dereferenced (%#lx)", this->RealPointer);
return *this->RealPointer;
}
T *operator->()
{
spdbg("Smart pointer dereferenced (%#lx)", this->RealPointer);
return this->RealPointer;
}
T *get()
{
spdbg("Smart pointer returned (%#lx)", this->RealPointer);
return this->RealPointer;
}
};
template <class T>
class auto_ptr
{
};
template <class T>
class unique_ptr
{
};
template <class T>
class weak_ptr
{
};
template <typename T>
class shared_ptr
{
private:
class counter
{
private:
unsigned int RefCount{};
public:
counter() : RefCount(0) { spdbg("Counter %#lx created", this); };
counter(const counter &) = delete;
counter &operator=(const counter &) = delete;
~counter() { spdbg("Counter %#lx deleted", this); }
void reset()
{
this->RefCount = 0;
spdbg("reset");
}
unsigned int get()
{
return this->RefCount;
spdbg("return");
}
void operator++()
{
this->RefCount++;
spdbg("increment");
}
void operator++(int)
{
this->RefCount++;
spdbg("increment");
}
void operator--()
{
this->RefCount--;
spdbg("decrement");
}
void operator--(int)
{
this->RefCount--;
spdbg("decrement");
}
};
counter *ReferenceCounter;
T *RealPointer;
public:
explicit shared_ptr(T *Pointer = nullptr)
{
this->RealPointer = Pointer;
this->ReferenceCounter = new counter();
spdbg("[%#lx] Shared pointer created (ptr=%#lx, ref=%#lx)", this, Pointer, this->ReferenceCounter);
if (Pointer)
(*this->ReferenceCounter)++;
}
shared_ptr(shared_ptr<T> &SPtr)
{
spdbg("[%#lx] Shared pointer copied (ptr=%#lx, ref=%#lx)", this, SPtr.RealPointer, SPtr.ReferenceCounter);
this->RealPointer = SPtr.RealPointer;
this->ReferenceCounter = SPtr.ReferenceCounter;
(*this->ReferenceCounter)++;
}
~shared_ptr()
{
spdbg("[%#lx] Shared pointer destructor called", this);
(*this->ReferenceCounter)--;
if (this->ReferenceCounter->get() == 0)
{
spdbg("[%#lx] Shared pointer deleted (ptr=%#lx, ref=%#lx)", this, this->RealPointer, this->ReferenceCounter);
delete this->ReferenceCounter, this->ReferenceCounter = nullptr;
delete this->RealPointer, this->RealPointer = nullptr;
}
}
unsigned int get_count()
{
spdbg("[%#lx] Shared pointer count (%d)", this, this->ReferenceCounter->get());
return this->ReferenceCounter->get();
}
T *get()
{
spdbg("[%#lx] Shared pointer get (%#lx)", this, this->RealPointer);
return this->RealPointer;
}
T &operator*()
{
spdbg("[%#lx] Shared pointer dereference (ptr*=%#lx)", this, *this->RealPointer);
return *this->RealPointer;
}
T *operator->()
{
spdbg("[%#lx] Shared pointer dereference (ptr->%#lx)", this, this->RealPointer);
return this->RealPointer;
}
void reset(T *Pointer = nullptr)
{
if (this->RealPointer == Pointer)
return;
spdbg("[%#lx] Shared pointer reset (ptr=%#lx, ref=%#lx)", this, Pointer, this->ReferenceCounter);
(*this->ReferenceCounter)--;
if (this->ReferenceCounter->get() == 0)
{
delete this->RealPointer;
delete this->ReferenceCounter;
}
this->RealPointer = Pointer;
this->ReferenceCounter = new counter();
if (Pointer)
(*this->ReferenceCounter)++;
}
void reset()
{
spdbg("[%#lx] Shared pointer reset (ptr=%#lx, ref=%#lx)", this, this->RealPointer, this->ReferenceCounter);
if (this->ReferenceCounter->get() == 1)
{
delete this->RealPointer, this->RealPointer = nullptr;
delete this->ReferenceCounter, this->ReferenceCounter = nullptr;
}
else
{
(*this->ReferenceCounter)--;
}
}
void swap(shared_ptr<T> &Other)
{
spdbg("[%#lx] Shared pointer swap (ptr=%#lx, ref=%#lx <=> ptr=%#lx, ref=%#lx)",
this, this->RealPointer, this->ReferenceCounter, Other.RealPointer, Other.ReferenceCounter);
T *tempRealPointer = this->RealPointer;
counter *tempReferenceCounter = this->ReferenceCounter;
this->RealPointer = Other.RealPointer;
this->ReferenceCounter = Other.ReferenceCounter;
Other.RealPointer = tempRealPointer;
Other.ReferenceCounter = tempReferenceCounter;
}
};
template <typename T, typename... Args>
shared_ptr<T> make_shared(Args &&...args)
{
return shared_ptr<T>(new T(forward<Args>(args)...));
};
template <typename T, typename... Args>
smart_ptr<T> make_smart(Args &&...args)
{
return smart_ptr<T>(new T(forward<Args>(args)...));
};
}
#endif // !__FENNIX_KERNEL_STD_SMART_POINTER_H__

35
include_std/stdbool.h Normal file
View File

@ -0,0 +1,35 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __FENNIX_KERNEL_header_H__
#define __FENNIX_KERNEL_header_H__
#include <types.h>
#ifndef __cplusplus
#define bool _Bool
#define true 1
#define false 0
#else
#define _Bool bool
#endif // !__cplusplus
#endif // !__FENNIX_KERNEL_header_H__

View File

@ -17,27 +17,103 @@
#pragma once
#include <assert.h>
#include <convert.h>
#include <cassert>
#include <new>
namespace std
{
class runtime_error
class __simple_string
{
private:
const char *m_what;
char *data;
size_t size;
public:
runtime_error(const char *what_arg) : m_what(what_arg) {}
const char *what() const { return this->m_what; }
};
class out_of_range
{
public:
out_of_range(const char *what_arg)
__simple_string()
: data(nullptr),
size(0)
{
/* FIXME: This is a temporary assert */
assert(what_arg != nullptr);
}
__simple_string(const char *str)
: data(nullptr),
size(0)
{
size = strlen(str);
data = new char[size + 1];
assert(data != nullptr);
memcpy(data, str, size);
data[size] = '\0';
}
__simple_string(const __simple_string &other)
: data(nullptr),
size(0)
{
size = other.size;
data = new char[size + 1];
assert(data != nullptr);
memcpy(data, other.data, size);
data[size] = '\0';
}
~__simple_string()
{
if (data)
delete[] data;
}
const char *c_str() const { return data; }
__simple_string &operator=(const __simple_string &other)
{
if (data)
delete[] data;
size = other.size;
data = new char[size + 1];
assert(data != nullptr);
memcpy(data, other.data, size);
data[size] = '\0';
return *this;
}
};
class runtime_error : public exception
{
};
class logic_error : public exception
{
private:
__simple_string msg;
public:
logic_error(const char *what_arg) : msg(what_arg) {}
logic_error(const logic_error &other) : msg(other.msg) {}
logic_error &operator=(const logic_error &other) noexcept
{
msg = other.msg;
return *this;
}
virtual const char *what() const noexcept
{
return msg.c_str();
}
};
class out_of_range : public logic_error
{
public:
out_of_range(const char *what_arg) : logic_error(what_arg) {}
out_of_range(const out_of_range &other) = default;
out_of_range &operator=(const out_of_range &) = default;
out_of_range(out_of_range &&) = default;
out_of_range &operator=(out_of_range &&) = default;
virtual ~out_of_range() = default;
};
}

View File

@ -15,7 +15,42 @@
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef _STDIO_H
#define _STDIO_H
#ifndef __FENNIX_KERNEL_STDIO_H__
#define __FENNIX_KERNEL_STDIO_H__
#endif // !_STDIO_H
#include <types.h>
START_EXTERNC
#define FILENAME_MAX 4096
typedef struct
{
int st;
} FILE;
extern FILE *stdin;
extern FILE *stdout;
extern FILE *stderr;
#define stdin stdin
#define stdout stdout
#define stderr stderr
int printf(const char *format, ...) __attribute__((format(__printf__, (1), (2))));
int vprintf(const char *format, va_list arg) __attribute__((format(__printf__, ((1)), (0))));
int sprintf(char *s, const char *format, ...) __attribute__((format(__printf__, (2), (3))));
int vsprintf(char *s, const char *format, va_list arg) __attribute__((format(__printf__, ((2)), (0))));
int snprintf(char *s, size_t count, const char *format, ...) __attribute__((format(__printf__, (3), (4))));
int vsnprintf(char *s, size_t count, const char *format, va_list arg) __attribute__((format(__printf__, ((3)), (0))));
int asprintf(char **strp, const char *fmt, ...) __attribute__((format(__printf__, (2), (3))));
int vasprintf(char **strp, const char *fmt, va_list ap) __attribute__((format(__printf__, ((2)), (0))));
int fprintf(FILE *stream, const char *format, ...) __attribute__((format(__printf__, (2), (3))));
int fputs(const char *s, FILE *stream);
END_EXTERNC
#endif // !__FENNIX_KERNEL_STDIO_H__

View File

@ -15,7 +15,27 @@
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef _STDLIB_H
#define _STDLIB_H
#ifndef __FENNIX_KERNEL_STDLIB_H__
#define __FENNIX_KERNEL_STDLIB_H__
#endif // !_STDLIB_H
#include <types.h>
START_EXTERNC
#ifndef __FENNIX_KERNEL_INTERNAL_MEMORY_H__
void *malloc(size_t Size);
void *calloc(size_t n, size_t Size);
void *realloc(void *Address, size_t Size);
void free(void *Address);
#endif // !__FENNIX_KERNEL_INTERNAL_MEMORY_H__
void abort();
#define EXIT_FAILURE 1
#define EXIT_SUCCESS 0
END_EXTERNC
#endif // !__FENNIX_KERNEL_STDLIB_H__

312
include_std/streambuf Normal file
View File

@ -0,0 +1,312 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <algorithm>
#include <string>
#include <locale>
#include <ios>
namespace std
{
template <class CharT, class Traits = std::char_traits<CharT>>
class basic_streambuf
{
public:
typedef CharT char_type;
typedef Traits::char_type traits_type;
typedef Traits::int_type int_type;
typedef Traits::pos_type pos_type;
typedef Traits::off_type off_type;
private:
char_type *_eback;
char_type *_gptr;
char_type *_egptr;
char_type *_pbase;
char_type *_pptr;
char_type *_epptr;
public:
virtual ~basic_streambuf();
#pragma region Locales
std::locale pubimbue(const std::locale &loc)
{
return imbue(loc);
}
std::locale getloc() const
{
return imbue(std::locale());
}
#pragma endregion Locales
#pragma region Positioning
basic_streambuf<CharT, Traits> *pubsetbuf(char_type *s, std::streamsize n)
{
return setbuf(s, n);
}
pos_type pubseekoff(off_type off, std::ios_base::seekdir dir, std::ios_base::openmode which = ios_base::in | ios_base::out)
{
return seekoff(off, dir, which);
}
pos_type pubseekpos(pos_type pos, std::ios_base::openmode which = std::ios_base::in | std::ios_base::out)
{
return seekpos(pos, which);
}
int pubsync()
{
return sync();
}
#pragma endregion Positioning
#pragma region Get Area
std::streamsize in_avail()
{
return egptr() - gptr();
}
int_type snextc()
{
return gptr() == egptr() ? Traits::eof() : Traits::to_int_type(*gptr());
}
int_type sgetc()
{
return gptr() == egptr() ? underflow() : Traits::to_int_type(*gptr());
}
std::streamsize sgetn(char_type *s, std::streamsize count)
{
std::streamsize copied = 0;
while (copied < count)
{
if (gptr() == egptr())
{
if (underflow() == Traits::eof())
{
break;
}
}
*s++ = *gptr();
++copied;
}
return copied;
}
#pragma endregion Get Area
#pragma region Put Area
int_type sputc(char_type ch)
{
if (pptr() == epptr())
{
if (overflow(Traits::to_int_type(ch)) == Traits::eof())
{
return Traits::eof();
}
}
else
{
*pptr() = ch;
pbump(1);
}
return Traits::to_int_type(ch);
}
std::streamsize sputn(const char_type *s, std::streamsize count)
{
return xsputn(s, count);
}
#pragma endregion Put Area
#pragma region Putback
int_type sputbackc(char_type c)
{
if (gptr() == eback() || !Traits::eq(c, gptr()[-1]))
{
return Traits::eof();
}
gbump(-1);
return Traits::to_int_type(c);
}
int_type sungetc()
{
if (gptr() == eback())
{
return Traits::eof();
}
gbump(-1);
return Traits::to_int_type(*gptr());
}
#pragma endregion Putback
protected:
basic_streambuf()
: _eback(nullptr),
_gptr(nullptr),
_egptr(nullptr),
_pbase(nullptr),
_pptr(nullptr),
_epptr(nullptr)
{
}
basic_streambuf(const basic_streambuf &rhs)
: _eback(rhs._eback),
_gptr(rhs._gptr),
_egptr(rhs._egptr),
_pbase(rhs._pbase),
_pptr(rhs._pptr),
_epptr(rhs._epptr)
{
}
basic_streambuf &operator=(const basic_streambuf &other)
{
if (this == &other)
return *this;
_eback = other._eback;
_gptr = other._gptr;
_egptr = other._egptr;
_pbase = other._pbase;
_pptr = other._pptr;
_epptr = other._epptr;
return *this;
}
void swap(basic_streambuf &other)
{
std::swap(_eback, other._eback);
std::swap(_gptr, other._gptr);
std::swap(_egptr, other._egptr);
std::swap(_pbase, other._pbase);
std::swap(_pptr, other._pptr);
std::swap(_epptr, other._epptr);
}
#pragma region Locales
virtual void imbue(const std::locale &loc) = 0;
#pragma endregion Locales
#pragma region Positioning
virtual basic_streambuf<CharT, Traits> *setbuf(char_type *s, std::streamsize n) = 0;
virtual pos_type seekoff(off_type off, std::ios_base::seekdir dir, std::ios_base::openmode which = ios_base::in | ios_base::out) = 0;
virtual pos_type seekpos(pos_type pos, std::ios_base::openmode which = std::ios_base::in | std::ios_base::out) = 0;
virtual int sync() = 0;
#pragma endregion Positioning
#pragma region Get Area
virtual std::streamsize showmanyc() = 0;
virtual int_type underflow() = 0;
virtual int_type uflow() = 0;
virtual std::streamsize xsgetn(char_type *s, std::streamsize count) = 0;
char_type *eback() const
{
return _eback;
}
char_type *gptr() const
{
return _gptr;
}
char_type *egptr() const
{
return _egptr;
}
void gbump(int count)
{
_gptr += count;
}
void setg(char_type *gbeg, char_type *gcurr, char_type *gend)
{
_eback = gbeg;
_gptr = gcurr;
_egptr = gend;
}
#pragma endregion Get Area
#pragma region Put Area
virtual std::streamsize xsputn(const char_type *s, std::streamsize count) = 0;
virtual int_type overflow(int_type ch = Traits::eof()) = 0;
char_type *pbase() const
{
return _pbase;
}
char_type *pptr() const
{
return _pptr;
}
char_type *epptr() const
{
return _epptr;
}
void pbump(int count)
{
_pptr += count;
}
void setp(char_type *pbeg, char_type *pend)
{
_pbase = pbeg;
_pptr = pbeg;
_epptr = pend;
}
#pragma endregion Put Area
#pragma region Putback
virtual int_type pbackfail(int_type c = Traits::eof()) = 0;
#pragma endregion Putback
};
typedef basic_streambuf<char> streambuf;
typedef basic_streambuf<wchar_t> wstreambuf;
}

File diff suppressed because it is too large Load Diff

62
include_std/string_view Normal file
View File

@ -0,0 +1,62 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <string>
#include <ostream>
namespace std
{
typedef basic_string_view<char> string_view;
typedef basic_string_view<wchar_t> wstring_view;
typedef basic_string_view<char8_t> u8string_view;
typedef basic_string_view<char16_t> u16string_view;
typedef basic_string_view<char32_t> u32string_view;
template <class CharT, class Traits>
std::basic_ostream<CharT, Traits> &operator<<(std::basic_ostream<CharT, Traits> &os, std::basic_string_view<CharT, Traits> v)
{
os.write(v.data(), v.size());
return os;
}
constexpr std::string_view operator""sv(const char *str, std::size_t len) noexcept
{
return std::string_view{str, len};
}
constexpr std::u8string_view operator""sv(const char8_t *str, std::size_t len) noexcept
{
return std::u8string_view{str, len};
}
constexpr std::u16string_view operator""sv(const char16_t *str, std::size_t len) noexcept
{
return std::u16string_view{str, len};
}
constexpr std::u32string_view operator""sv(const char32_t *str, std::size_t len) noexcept
{
return std::u32string_view{str, len};
}
constexpr std::wstring_view operator""sv(const wchar_t *str, std::size_t len) noexcept
{
return std::wstring_view{str, len};
}
}

View File

@ -18,7 +18,7 @@
#pragma once
#include <types.h>
/* stubs */
/* stubs for rpmalloc.c */
#ifndef MAP_PRIVATE
#define MAP_PRIVATE 0x0

58
include_std/system_error Normal file
View File

@ -0,0 +1,58 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
namespace std
{
class error_category
{
/* https://en.cppreference.com/w/cpp/error/error_category */
};
class error_code
{
public:
error_code() noexcept
{
}
error_code(int ec, const error_category &ecat) noexcept
{
}
template <class ErrorCodeEnum>
error_code(ErrorCodeEnum e) noexcept
{
}
error_code(const error_code &other) = default;
error_code(error_code &&other) = default;
template <class ErrorCodeEnum>
error_code &operator=(ErrorCodeEnum e) noexcept
{
return *this;
}
error_code &operator=(const error_code &other) = default;
error_code &operator=(error_code &&other) = default;
/* https://en.cppreference.com/w/cpp/error/error_code */
};
}

187
include_std/termios.h Normal file
View File

@ -0,0 +1,187 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __FENNIX_KERNEL_TERMIOS_H__
#define __FENNIX_KERNEL_TERMIOS_H__
#include <types.h>
/* c_cc */
#define VINTR 0
#define VQUIT 1
#define VERASE 2
#define VKILL 3
#define VEOF 4
#define VTIME 5
#define VMIN 6
#define VSWTC 7
#define VSTART 8
#define VSTOP 9
#define VSUSP 10
#define VEOL 11
#define VREPRINT 12
#define VDISCARD 13
#define VWERASE 14
#define VLNEXT 15
#define VEOL2 16
/* c_iflag */
#define IGNBRK 0000001
#define BRKINT 0000002
#define IGNPAR 0000004
#define PARMRK 0000010
#define INPCK 0000020
#define ISTRIP 0000040
#define INLCR 0000100
#define IGNCR 0000200
#define ICRNL 0000400
#define IUCLC 0001000
#define IXON 0002000
#define IXANY 0004000
#define IXOFF 0010000
#define IMAXBEL 0020000
#define IUTF8 0040000
/* c_lflag */
#define ISIG 0000001
#define ICANON 0000002
#define XCASE 0000004
#define ECHO 0000010
#define ECHOE 0000020
#define ECHOK 0000040
#define ECHONL 0000100
#define NOFLSH 0000200
#define TOSTOP 0000400
#define ECHOCTL 0001000
#define ECHOPRT 0002000
#define ECHOKE 0004000
#define FLUSHO 0010000
#define PENDIN 0040000
#define IEXTEN 0100000
#define EXTPROC 0200000
/* c_oflag */
#define OPOST 0000001
#define OLCUC 0000002
#define ONLCR 0000004
#define OCRNL 0000010
#define ONOCR 0000020
#define ONLRET 0000040
#define OFILL 0000100
#define OFDEL 0000200
#define NLDLY 0000400
#define NL0 0000000
#define NL1 0000400
#define CRDLY 0003000
#define _CR0 0000000
#define _CR1 0001000
#define _CR2 0002000
#define _CR3 0003000
#define TABDLY 0014000
#define TAB0 0000000
#define TAB1 0004000
#define TAB2 0010000
#define TAB3 0014000
#define XTABS 0014000
#define BSDLY 0020000
#define BS0 0000000
#define BS1 0020000
#define VTDLY 0040000
#define VT0 0000000
#define VT1 0040000
#define FFDLY 0100000
#define FF0 0000000
#define FF1 0100000
/* c_cflag */
#define CBAUD 0010017
#define _B0 0000000
#define B50 0000001
#define B75 0000002
#define B110 0000003
#define B134 0000004
#define B150 0000005
#define B200 0000006
#define B300 0000007
#define B600 0000010
#define B1200 0000011
#define B1800 0000012
#define B2400 0000013
#define B4800 0000014
#define B9600 0000015
#define B19200 0000016
#define B38400 0000017
#define EXTA B19200
#define EXTB B38400
#define CSIZE 0000060
#define CS5 0000000
#define CS6 0000020
#define CS7 0000040
#define CS8 0000060
#define CSTOPB 0000100
#define CREAD 0000200
#define PARENB 0000400
#define PARODD 0001000
#define HUPCL 0002000
#define CLOCAL 0004000
#define CBAUDEX 0010000
#define BOTHER 0010000
#define B57600 0010001
#define B115200 0010002
#define B230400 0010003
#define B460800 0010004
#define B500000 0010005
#define B576000 0010006
#define B921600 0010007
#define B1000000 0010010
#define B1152000 0010011
#define B1500000 0010012
#define B2000000 0010013
#define B2500000 0010014
#define B3000000 0010015
#define B3500000 0010016
#define B4000000 0010017
#define CIBAUD 002003600000
#define CMSPAR 010000000000
#define CRTSCTS 020000000000
typedef unsigned char cc_t;
typedef unsigned int speed_t;
typedef unsigned int tcflag_t;
#define NCCS 32
struct termios
{
tcflag_t c_iflag;
tcflag_t c_oflag;
tcflag_t c_cflag;
tcflag_t c_lflag;
cc_t c_line;
cc_t c_cc[NCCS];
speed_t c_ispeed;
speed_t c_ospeed;
};
struct winsize
{
unsigned short ws_row;
unsigned short ws_col;
unsigned short ws_xpixel;
unsigned short ws_ypixel;
};
#endif // !__FENNIX_KERNEL_TERMIOS_H__

27
include_std/tuple Normal file
View File

@ -0,0 +1,27 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <type_traits>
#include <cstddef>
namespace std
{
template <class... Types>
class tuple;
}

View File

@ -19,6 +19,33 @@
namespace std
{
template <class T>
struct add_cv
{
typedef const volatile T type;
};
template <class T>
struct add_const
{
typedef const T type;
};
template <class T>
struct add_volatile
{
typedef volatile T type;
};
template <class T>
using add_cv_t = typename add_cv<T>::type;
template <class T>
using add_const_t = typename add_const<T>::type;
template <class T>
using add_volatile_t = typename add_volatile<T>::type;
template <typename T>
struct is_trivially_copyable
{
@ -43,6 +70,9 @@ namespace std
typedef T type;
};
template <class T>
using remove_reference_t = typename remove_reference<T>::type;
template <class T, T v>
struct integral_constant
{
@ -53,6 +83,569 @@ namespace std
constexpr value_type operator()() const noexcept { return value; }
};
template <class T>
struct is_array : public integral_constant<bool, false>
{
};
template <class T>
struct is_array<T[]> : public integral_constant<bool, true>
{
};
template <class T, __SIZE_TYPE__ N>
struct is_array<T[N]> : public integral_constant<bool, true>
{
};
template <class T>
inline constexpr bool is_array_v = is_array<T>::value;
template <bool B, class T, class F>
struct conditional
{
typedef T type;
};
template <class T, class F>
struct conditional<false, T, F>
{
typedef F type;
};
template <bool B, class T, class F>
using conditional_t = typename conditional<B, T, F>::type;
template <class T>
struct type_identity
{
using type = T;
};
template <class T>
using type_identity_t = type_identity<T>::type;
template <class T>
auto __try_add_pointer(int) -> type_identity<typename std::remove_reference<T>::type *>;
template <class T>
auto __try_add_pointer(...) -> type_identity<T>;
template <class T>
struct add_pointer : decltype(__try_add_pointer<T>(0))
{
};
template <class T>
using add_pointer_t = typename add_pointer<T>::type;
template <class T>
struct remove_extent
{
using type = T;
};
template <class T>
struct remove_extent<T[]>
{
using type = T;
};
template <class T, __SIZE_TYPE__ N>
struct remove_extent<T[N]>
{
using type = T;
};
template <class T>
using remove_extent_t = typename remove_extent<T>::type;
template <class T>
struct remove_cv
{
typedef T type;
};
template <class T>
struct remove_cv<const T>
{
typedef T type;
};
template <class T>
struct remove_cv<volatile T>
{
typedef T type;
};
template <class T>
struct remove_cv<const volatile T>
{
typedef T type;
};
template <class T>
struct remove_const
{
typedef T type;
};
template <class T>
struct remove_const<const T>
{
typedef T type;
};
template <class T>
struct remove_volatile
{
typedef T type;
};
template <class T>
struct remove_volatile<volatile T>
{
typedef T type;
};
template <class T>
using remove_cv_t = typename remove_cv<T>::type;
template <class T>
using remove_const_t = typename remove_const<T>::type;
template <class T>
using remove_volatile_t = typename remove_volatile<T>::type;
template <class T>
struct is_lvalue_reference : public integral_constant<bool, false>
{
};
template <class T>
struct is_lvalue_reference<T &> : public integral_constant<bool, true>
{
};
template <class T>
inline constexpr bool is_lvalue_reference_v = is_lvalue_reference<T>::value;
template <class T>
struct is_const : public integral_constant<bool, false>
{
};
template <class T>
struct is_const<const T> : public integral_constant<bool, true>
{
};
template <class T>
inline constexpr bool is_const_v = is_const<T>::value;
template <class T>
struct is_reference : public integral_constant<bool, false>
{
};
template <class T>
struct is_reference<T &> : public integral_constant<bool, true>
{
};
template <class T>
struct is_reference<T &&> : public integral_constant<bool, true>
{
};
template <class T>
inline constexpr bool is_reference_v = is_reference<T>::value;
template <class T>
struct is_function : std::integral_constant<
bool,
!std::is_const<const T>::value && !std::is_reference<T>::value>
{
};
template <class T>
struct decay
{
private:
typedef typename std::remove_reference<T>::type U;
public:
typedef typename std::conditional<
std::is_array<U>::value,
typename std::add_pointer<typename std::remove_extent<U>::type>::type,
typename std::conditional<
std::is_function<U>::value,
typename std::add_pointer<U>::type,
typename std::remove_cv<U>::type>::type>::type type;
};
template <class T>
using decay_t = typename decay<T>::type;
template <bool B>
using bool_constant = integral_constant<bool, B>;
typedef integral_constant<bool, true> true_type;
typedef integral_constant<bool, false> false_type;
template <bool, class T = void>
struct enable_if
{
};
template <class T>
struct enable_if<true, T>
{
typedef T type;
};
template <bool B, class T = void>
using enable_if_t = typename enable_if<B, T>::type;
template <class T>
auto __try_add_lvalue_reference(int) -> type_identity<T &>;
template <class T>
auto __try_add_lvalue_reference(...) -> type_identity<T>;
template <class T>
auto __try_add_rvalue_reference(int) -> type_identity<T &&>;
template <class T>
auto __try_add_rvalue_reference(...) -> type_identity<T>;
template <class T>
struct add_lvalue_reference : decltype(__try_add_lvalue_reference<T>(0))
{
};
template <class T>
struct add_rvalue_reference : decltype(__try_add_rvalue_reference<T>(0))
{
};
template <class T>
using add_lvalue_reference_t = typename add_lvalue_reference<T>::type;
template <class T>
using add_rvalue_reference_t = typename add_rvalue_reference<T>::type;
template <typename T>
typename std::add_rvalue_reference<T>::type declval() noexcept
{
static_assert(false, "declval not allowed in an evaluated context");
}
template <class T, class... Args>
struct is_constructible : public integral_constant<bool, __is_constructible(T, Args...)>
{
};
template <class T, class... Args>
struct is_trivially_constructible : public integral_constant<bool, __is_trivially_constructible(T, Args...)>
{
};
template <class T, class... Args>
struct is_nothrow_constructible : public integral_constant<bool, __is_nothrow_constructible(T, Args...)>
{
};
template <class T, class... Args>
inline constexpr bool is_constructible_v = is_constructible<T, Args...>::value;
template <class T, class... Args>
inline constexpr bool is_trivially_constructible_v = is_trivially_constructible<T, Args...>::value;
template <class T, class... Args>
inline constexpr bool is_nothrow_constructible_v = is_nothrow_constructible<T, Args...>::value;
template <class T>
struct is_default_constructible : std::is_constructible<T>
{
};
template <class T>
struct is_trivially_default_constructible : std::is_trivially_constructible<T>
{
};
template <class T>
struct is_nothrow_default_constructible : std::is_nothrow_constructible<T>
{
};
template <class T>
inline constexpr bool is_default_constructible_v = is_default_constructible<T>::value;
template <class T>
inline constexpr bool is_trivially_default_constructible_v = is_trivially_default_constructible<T>::value;
template <class T>
inline constexpr bool is_nothrow_default_constructible_v = is_nothrow_default_constructible<T>::value;
template <class T, class U>
struct is_assignable : public integral_constant<bool, __is_assignable(T, U)>
{
};
template <class T, class U>
struct is_trivially_assignable : public integral_constant<bool, __is_trivially_assignable(T, U)>
{
};
template <class T, class U>
struct is_nothrow_assignable : public integral_constant<bool, __is_nothrow_assignable(T, U)>
{
};
template <class T, class U>
inline constexpr bool is_assignable_v = is_assignable<T, U>::value;
template <class T, class U>
inline constexpr bool is_trivially_assignable_v = is_trivially_assignable<T, U>::value;
template <class T, class U>
inline constexpr bool is_nothrow_assignable_v = is_nothrow_assignable<T, U>::value;
template <class T>
struct is_move_assignable : std::is_assignable<typename std::add_lvalue_reference<T>::type, typename std::add_rvalue_reference<T>::type>
{
};
template <class T>
struct is_trivially_move_assignable : std::is_trivially_assignable<typename std::add_lvalue_reference<T>::type, typename std::add_rvalue_reference<T>::type>
{
};
template <class T>
struct is_nothrow_move_assignable : std::is_nothrow_assignable<typename std::add_lvalue_reference<T>::type, typename std::add_rvalue_reference<T>::type>
{
};
template <class T>
inline constexpr bool is_move_assignable_v = is_move_assignable<T>::value;
template <class T>
inline constexpr bool is_trivially_move_assignable_v = is_trivially_move_assignable<T>::value;
template <class T>
inline constexpr bool is_nothrow_move_assignable_v = is_nothrow_move_assignable<T>::value;
template <class T>
struct is_move_constructible : std::is_constructible<T, typename std::add_rvalue_reference<T>::type>
{
};
template <class T>
struct is_trivially_move_constructible : std::is_trivially_constructible<T, typename std::add_rvalue_reference<T>::type>
{
};
template <class T>
struct is_nothrow_move_constructible : std::is_nothrow_constructible<T, typename std::add_rvalue_reference<T>::type>
{
};
template <class T>
inline constexpr bool is_move_constructible_v = is_move_constructible<T>::value;
template <class T>
inline constexpr bool is_trivially_move_constructible_v = is_trivially_move_constructible<T>::value;
template <class T>
inline constexpr bool is_nothrow_move_constructible_v = is_nothrow_move_constructible<T>::value;
template <typename T>
typename std::remove_reference<T>::type &&__type_traits_move(T &&arg)
{
return static_cast<typename std::remove_reference<T>::type &&>(arg);
}
template <typename T>
void __type_traits_swap(T &a, T &b)
{
T temp = __type_traits_move(a);
a = __type_traits_move(b);
b = __type_traits_move(temp);
}
template <class T, class U>
struct is_swappable_with
{
template <class X, class Y,
typename = decltype(__type_traits_swap(std::declval<X>(), std::declval<Y>())),
typename = decltype(__type_traits_swap(std::declval<Y>(), std::declval<X>()))>
static std::true_type test(int);
template <class, class>
static std::false_type test(...);
static constexpr bool value = decltype(test<T, U>(0))::value;
};
template <class T>
struct is_swappable
{
static constexpr bool value = is_swappable_with<T, T>::value;
};
template <class T, class U>
struct is_nothrow_swappable_with
{
template <class X, class Y,
typename = decltype(__type_traits_swap(std::declval<X>(), std::declval<Y>())),
typename = decltype(__type_traits_swap(std::declval<Y>(), std::declval<X>()))>
static std::true_type test(int);
template <class, class>
static std::false_type test(...);
static constexpr bool value = decltype(test<T, U>(0))::value;
};
template <class T>
struct is_nothrow_swappable
{
static constexpr bool value = is_nothrow_swappable_with<T, T>::value;
};
template <class T, class U>
inline constexpr bool is_swappable_with_v = is_swappable_with<T, U>::value;
template <class T>
inline constexpr bool is_swappable_v = is_swappable<T>::value;
template <class T, class U>
inline constexpr bool is_nothrow_swappable_with_v = is_nothrow_swappable_with<T, U>::value;
template <class T>
inline constexpr bool is_nothrow_swappable_v = is_nothrow_swappable<T>::value;
template <class T>
struct is_copy_constructible : std::is_constructible<T, typename std::add_lvalue_reference<typename std::add_const<T>::type>::type>
{
};
template <class T>
struct is_trivially_copy_constructible : std::is_trivially_constructible<T, typename std::add_lvalue_reference<typename std::add_const<T>::type>::type>
{
};
template <class T>
struct is_nothrow_copy_constructible : std::is_nothrow_constructible<T, typename std::add_lvalue_reference<typename std::add_const<T>::type>::type>
{
};
template <class T>
inline constexpr bool is_copy_constructible_v = is_copy_constructible<T>::value;
template <class T>
inline constexpr bool is_trivially_copy_constructible_v = is_trivially_copy_constructible<T>::value;
template <class T>
inline constexpr bool is_nothrow_copy_constructible_v = is_nothrow_copy_constructible<T>::value;
template <class T, class U>
struct is_same : std::false_type
{
};
template <class T>
struct is_same<T, T> : std::true_type
{
};
template <class T, class U>
inline constexpr bool is_same_v = is_same<T, U>::value;
template <class T>
struct is_unbounded_array : std::false_type
{
};
template <class T>
struct is_unbounded_array<T[]> : std::true_type
{
};
template <class T>
inline constexpr bool is_unbounded_array_v = is_unbounded_array<T>::value;
template <class T>
struct is_bounded_array : std::false_type
{
};
template <class T, __SIZE_TYPE__ N>
struct is_bounded_array<T[N]> : std::true_type
{
};
template <class T>
inline constexpr bool is_bounded_array_v = is_bounded_array<T>::value;
template <class...>
struct common_type
{
};
template <class T>
struct common_type<T> : common_type<T, T>
{
};
namespace __type_traits_detail
{
template <class...>
using void_t = void;
template <class T1, class T2>
using conditional_result_t = decltype(false ? std::declval<T1>() : std::declval<T2>());
template <class, class, class = void>
struct decay_conditional_result
{
};
template <class T1, class T2>
struct decay_conditional_result<T1, T2, void_t<conditional_result_t<T1, T2>>> : std::decay<conditional_result_t<T1, T2>>
{
};
template <class T1, class T2, class = void>
struct common_type_2_impl : decay_conditional_result<const T1 &, const T2 &>
{
};
template <class T1, class T2>
struct common_type_2_impl<T1, T2, void_t<conditional_result_t<T1, T2>>> : decay_conditional_result<T1, T2>
{
};
template <class AlwaysVoid, class T1, class T2, class... R>
struct common_type_multi_impl
{
};
template <class T1, class T2, class... R>
struct common_type_multi_impl<void_t<typename common_type<T1, T2>::type>, T1, T2, R...> : common_type<typename common_type<T1, T2>::type, R...>
{
};
}
template <class T1, class T2>
struct common_type<T1, T2> : std::conditional<std::is_same<T1, typename std::decay<T1>::type>::value &&
std::is_same<T2, typename std::decay<T2>::type>::value,
__type_traits_detail::common_type_2_impl<T1, T2>,
common_type<typename std::decay<T1>::type, typename std::decay<T2>::type>>::type
{
};
template <class T1, class T2, class... R>
struct common_type<T1, T2, R...> : __type_traits_detail::common_type_multi_impl<void, T1, T2, R...>
{
};
template <class... T>
using common_type_t = typename common_type<T...>::type;
}

View File

@ -18,8 +18,8 @@
#ifndef __FENNIX_KERNEL_TYPEINFO_H__
#define __FENNIX_KERNEL_TYPEINFO_H__
#include <types.h>
#include <exception>
#include <cstddef>
namespace __cxxabiv1
{
@ -31,26 +31,33 @@ namespace std
{
class type_info
{
protected:
const char *Name;
explicit type_info(const char *n) : Name(n) {}
public:
type_info() = delete;
type_info(const type_info &) = delete;
virtual ~type_info();
bool operator==(const type_info &Argument) const noexcept
type_info &operator=(const type_info &) = delete;
type_info &operator=(type_info &&) = delete;
constexpr bool operator==(const type_info &rhs) const noexcept
{
return ((Name == Argument.Name) ||
(Name[0] != '*' &&
__builtin_strcmp(Name, Argument.Name) == 0));
return this == &rhs;
}
bool operator!=(const type_info &Argument) const noexcept
bool before(const type_info &rhs) const noexcept
{
return !operator==(Argument);
return (Name[0] == '*' && rhs.Name[0] == '*')
? Name < rhs.Name
: __builtin_strcmp(Name, rhs.Name) < 0;
}
bool before(const type_info &Argument) const noexcept
std::size_t hash_code() const noexcept
{
return (Name[0] == '*' && Argument.Name[0] == '*')
? Name < Argument.Name
: __builtin_strcmp(Name, Argument.Name) < 0;
return reinterpret_cast<std::size_t>(this);
}
const char *name() const noexcept
@ -68,20 +75,8 @@ namespace std
return Name[0] == '(';
}
virtual bool __do_catch(const type_info *ThrowType,
void **ThrowObject,
unsigned Outer) const;
virtual bool __do_upcast(const __cxxabiv1::__class_type_info *Target,
void **ObjectPointer) const;
protected:
const char *Name;
explicit type_info(const char *n) : Name(n) {}
private:
type_info &operator=(const type_info &);
type_info(const type_info &);
virtual bool __do_catch(const type_info *ThrowType, void **ThrowObject, unsigned Outer) const;
virtual bool __do_upcast(const __cxxabiv1::__class_type_info *Target, void **ObjectPointer) const;
};
class bad_cast : public exception
@ -109,11 +104,13 @@ namespace __cxxabiv1
unsigned int Flags;
const std::type_info *Pointee;
explicit __pbase_type_info(const char *n, int Qualifiers,
const std::type_info *Type)
explicit __pbase_type_info(const char *n, int Qualifiers, const std::type_info *Type)
: std::type_info(n),
Flags(Qualifiers),
Pointee(Type) {}
Pointee(Type)
{
}
virtual ~__pbase_type_info();
enum __masks
@ -207,18 +204,6 @@ namespace __cxxabiv1
}
};
/* FIXME: stub */
class __vmi_class_type_info /* : public __class_type_info */
{
public:
enum __flags_masks
{
__non_diamond_repeat_mask = 0x1,
__diamond_shaped_mask = 0x2,
__flags_unknown_mask = 0x10
};
};
class __class_type_info : public std::type_info
{
public:
@ -260,7 +245,7 @@ namespace __cxxabiv1
__sub_kind dst2src;
int whole_details;
__dyncast_result(int details_ = __vmi_class_type_info::__flags_unknown_mask)
__dyncast_result(int details_ = 0x10 /*__vmi_class_type_info::__flags_unknown_mask*/)
: dst_ptr(NULL),
whole2dst(__unknown),
whole2src(__unknown),
@ -300,6 +285,22 @@ namespace __cxxabiv1
unsigned Outer) const;
};
class __vmi_class_type_info : public __class_type_info
{
public:
enum __flags_masks
{
__non_diamond_repeat_mask = 0x1,
__diamond_shaped_mask = 0x2,
__flags_unknown_mask = 0x10
};
virtual ~__vmi_class_type_info();
virtual bool __do_upcast(const __class_type_info *target, void **thrown_object) const;
virtual void *cast_to(void *obj, const struct __class_type_info *other) const;
};
class __si_class_type_info : public __class_type_info
{
public:

File diff suppressed because it is too large Load Diff

View File

@ -1,78 +0,0 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __FENNIX_KERNEL_UNWIND_H__
#define __FENNIX_KERNEL_UNWIND_H__
#include <types.h>
enum _Unwind_Reason_Code
{
_URC_NO_REASON = 0,
_URC_FOREIGN_EXCEPTION_CAUGHT = 1,
_URC_FATAL_PHASE2_ERROR = 2,
_URC_FATAL_PHASE1_ERROR = 3,
_URC_NORMAL_STOP = 4,
_URC_END_OF_STACK = 5,
_URC_HANDLER_FOUND = 6,
_URC_INSTALL_CONTEXT = 7,
_URC_CONTINUE_UNWIND = 8
};
typedef void *_Unwind_Context_Reg_Val;
typedef unsigned _Unwind_Exception_Class __attribute__((__mode__(__DI__)));
typedef unsigned _Unwind_Ptr __attribute__((__mode__(__pointer__)));
typedef unsigned _Unwind_Word __attribute__((__mode__(__unwind_word__)));
typedef signed _Unwind_Sword __attribute__((__mode__(__unwind_word__)));
typedef int _Unwind_Action;
enum _UA : _Unwind_Action
{
_UA_SEARCH_PHASE = 1,
_UA_CLEANUP_PHASE = 2,
_UA_HANDLER_FRAME = 4,
_UA_FORCE_UNWIND = 8,
_UA_END_OF_STACK = 16
};
typedef void (*_Unwind_Exception_Cleanup_Fn)(_Unwind_Reason_Code,
struct _Unwind_Exception *);
typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)(int,
_Unwind_Action,
_Unwind_Exception_Class,
struct _Unwind_Exception *,
struct _Unwind_Context *);
struct _Unwind_Exception
{
_Unwind_Exception_Class exception_class;
_Unwind_Exception_Cleanup_Fn exception_cleanup;
_Unwind_Word private_1;
_Unwind_Word private_2;
} __attribute__((__aligned__));
struct _Unwind_Context;
struct _Unwind_FrameState
{
_Unwind_Personality_Fn personality;
};
EXTERNC _Unwind_Reason_Code _Unwind_RaiseException(_Unwind_Exception *Exception);
#endif // !__FENNIX_KERNEL_UNWIND_H__

View File

@ -18,37 +18,235 @@
#pragma once
#include <type_traits>
#include <algorithm>
#include <tuple>
namespace std
{
struct piecewise_construct_t
{
explicit piecewise_construct_t() = default;
};
inline constexpr std::piecewise_construct_t piecewise_construct{};
template <typename T>
typename std::remove_reference<T>::type &&move(T &&arg)
{
return static_cast<typename std::remove_reference<T>::type &&>(arg);
}
template <typename T>
void __utility_swap(T &a, T &b)
{
T temp = std::move(a);
a = std::move(b);
b = std::move(temp);
}
template <class T, T... Ints>
class integer_sequence
{
public:
typedef T value_type;
static constexpr std::size_t size() noexcept { return sizeof...(Ints); }
};
template <std::size_t... Ints>
using index_sequence = std::integer_sequence<std::size_t, Ints...>;
template <class T, T N>
using make_integer_sequence = std::integer_sequence<T, N>;
template <std::size_t N>
using make_index_sequence = std::make_integer_sequence<std::size_t, N>;
template <class... T>
using index_sequence_for = std::make_index_sequence<sizeof...(T)>;
template <class T>
constexpr T &&forward(std::remove_reference_t<T> &t) noexcept
{
return static_cast<T &&>(t);
}
template <class T>
constexpr T &&forward(std::remove_reference_t<T> &&t) noexcept
{
static_assert(!std::is_lvalue_reference<T>::value, "Can't forward an rvalue as an lvalue.");
return static_cast<T &&>(t);
}
template <typename T1, typename T2>
struct pair
{
typedef T1 first_type;
typedef T2 second_type;
T1 first;
T2 second;
first_type first;
second_type second;
pair() : first(T1()), second(T2()) {}
pair(const T1 &x, const T2 &y) : first(x), second(y) {}
template <typename U1 = T1,
typename U2 = T2,
typename std::enable_if<std::is_default_constructible<U1>::value &&
std::is_default_constructible<U2>::value,
int>::type = true>
constexpr pair()
: first(),
second()
{
}
template <typename U1 = T1,
typename U2 = T2,
typename std::enable_if<!std::is_default_constructible<U1>::value ||
!std::is_default_constructible<U2>::value,
int>::type = false>
explicit constexpr pair()
: first(),
second()
{
}
template <typename U1 = T1,
typename U2 = T2,
typename std::enable_if<std::is_copy_constructible<U1>::value &&
std::is_copy_constructible<U2>::value,
int>::type = true>
constexpr pair(const T1 &x, const T2 &y)
: first(x),
second(y)
{
}
template <typename U1 = T1,
typename U2 = T2,
typename std::enable_if<!std::is_copy_constructible<U1>::value ||
!std::is_copy_constructible<U2>::value,
int>::type = false>
explicit constexpr pair(const T1 &x, const T2 &y)
: first(x),
second(y)
{
}
template <typename U1 = T1,
typename U2 = T2,
typename std::enable_if<std::is_move_constructible<U1>::value &&
std::is_move_constructible<U2>::value,
int>::type = true>
constexpr pair(U1 &&x, U2 &&y)
: first(std::forward<U1>(x)),
second(std::forward<U2>(y))
{
}
template <typename U1 = T1,
typename U2 = T2,
typename std::enable_if<!std::is_move_constructible<U1>::value ||
!std::is_move_constructible<U2>::value,
int>::type = false>
explicit constexpr pair(T1 &&x, T2 &&y)
: first(std::forward<T1>(x)),
second(std::forward<T2>(y)){};
template <typename U1 = T1,
typename U2 = T2,
typename std::enable_if<std::is_copy_constructible<U1>::value &&
std::is_copy_constructible<U2>::value,
int>::type = true>
constexpr pair(const pair<U1, U2> &p)
: first(p.first),
second(p.second)
{
}
template <typename U1 = T1,
typename U2 = T2,
typename std::enable_if<!std::is_copy_constructible<U1>::value ||
!std::is_copy_constructible<U2>::value,
int>::type = false>
explicit constexpr pair(const pair<U1, U2> &p)
: first(p.first),
second(p.second)
{
}
template <typename U1 = T1,
typename U2 = T2,
typename std::enable_if<std::is_move_constructible<U1>::value &&
std::is_move_constructible<U2>::value,
int>::type = true>
constexpr pair(pair<U1, U2> &&p)
: first(std::forward<U1>(p.first)),
second(std::forward<U2>(p.second))
{
}
template <typename U1 = T1,
typename U2 = T2,
typename std::enable_if<!std::is_move_constructible<U1>::value ||
!std::is_move_constructible<U2>::value,
int>::type = false>
explicit constexpr pair(pair<U1, U2> &&p)
: first(std::forward<U1>(p.first)),
second(std::forward<U2>(p.second))
{
}
template <class... Args1, class... Args2>
constexpr pair(std::piecewise_construct_t, std::tuple<Args1...> first_args, std::tuple<Args2...> second_args)
: pair(first_args, second_args, std::index_sequence_for<Args1...>(), std::index_sequence_for<Args2...>())
{
}
pair(const pair &p) = default;
pair(pair &&p) = default;
constexpr pair &operator=(const pair &other)
{
first = other.first;
second = other.second;
return *this;
}
template <class U1, class U2>
constexpr pair &operator=(const pair<U1, U2> &other)
{
first = other.first;
second = other.second;
return *this;
}
constexpr pair &operator=(pair &&other) noexcept(std::is_nothrow_move_assignable<T1>::value && std::is_nothrow_move_assignable<T2>::value)
{
first = std::move(other.first);
second = std::move(other.second);
return *this;
}
template <class U1, class U2>
constexpr pair &operator=(pair<U1, U2> &&p)
{
first = std::forward<U1>(p.first);
second = std::forward<U2>(p.second);
return *this;
}
constexpr void swap(pair &other) noexcept(std::is_nothrow_swappable_v<first_type> && std::is_nothrow_swappable_v<second_type>)
{
__utility_swap(first, other.first);
__utility_swap(second, other.second);
}
};
template <typename T1, typename T2>
pair<T1, T2> make_pair(T1 x, T2 y)
template <class T1, class T2>
std::pair<typename std::decay<T1>::type, typename std::decay<T2>::type> make_pair(T1 &&t, T2 &&u)
{
return pair<T1, T2>(x, y);
typedef typename std::decay<T1>::type first_type;
typedef typename std::decay<T2>::type second_type;
typedef pair<first_type, second_type> pair_type;
return pair_type(std::forward<T1>(t), std::forward<T2>(u));
}
template <class T>
T &&forward(typename std::remove_reference<T>::type &arg)
{
return static_cast<T &&>(arg);
}
}
}

File diff suppressed because it is too large Load Diff