* http://libcxxabi.llvm.org/spec.html
*/
#include <cxxabi.h>
+#include <acess/sys.h>
namespace __cxxabiv1 {
}; // namespace __cxxabiv1
+extern "C" void __cxa_bad_cast ()
+{
+ _SysDebug("__cxa_bad_cast");
+ for(;;);
+ //throw ::std::bad_cast;
+}
+
+extern "C" void __cxa_bad_typeid ()
+{
+ _SysDebug("__cxa_bad_typeid");
+ for(;;);
+ //throw ::std::bad_typeid;
+}
+
#include <exception>
#include "exception_handling.h"
+#include <acess/sys.h>
- int uncaught_exception_count;
-__cxa_exception *uncaught_exception_top;
+/*__thread*/ struct __cxa_eh_globals {
+ __cxa_exception *caughtExceptions;
+ unsigned int uncaughtExceptions;
+} eh_globals;
/*__thread*/ struct {
__cxa_exception info;
}
// === CODE ===
+extern "C" __cxa_eh_globals *__cxa_get_globals(void)
+{
+ return &eh_globals;
+}
+extern "C" __cxa_eh_globals *__cxa_get_globals_fast(void)
+{
+ return &eh_globals;
+}
extern "C" void __cxa_call_unexpected(void *)
{
// An unexpected exception was thrown from a function that lists its possible exceptions
+ _SysDebug("__cxa_call_unexpected - TODO");
for(;;);
}
extern "C" void *__cxa_allocate_exception(size_t thrown_size)
{
+ ::_SysDebug("__cxa_allocate_exception(%i)", thrown_size);
__cxa_exception *ret = static_cast<__cxa_exception*>( malloc( sizeof(__cxa_exception) + thrown_size ) );
if( !ret ) {
if( thrown_size <= sizeof(emergency_exception.buf) && TEST_AND_SET(emergency_exception_used) )
}
}
if( !ret ) {
+ _SysDebug("__cxa_allocate_exception - No free space");
::std::terminate();
}
- return ret;
+ ::_SysDebug("__cxa_allocate_exception: return %p", ret+1);
+ return ret + 1;
}
extern "C" void __cxa_free_exception(void *thrown_exception)
{
+ ::_SysDebug("__cxa_free_exception(%p)", thrown_exception);
if(thrown_exception == &emergency_exception.buf) {
//assert(emergency_exception_used);
emergency_exception_used = false;
extern "C" void __cxa_throw(void *thrown_exception, std::type_info *tinfo, void (*dest)(void*))
{
+ ::_SysDebug("__cxa_throw(%p,%p,%p) '%s'", thrown_exception, tinfo, dest, tinfo->name());
+ {
+ const ::std::exception* e = reinterpret_cast<const ::std::exception*>(thrown_exception);
+ ::_SysDebug("- e.what() = '%s'", e->what());
+ }
+ ::_SysDebug("- typeid(*tinfo) = %p", &typeid(*tinfo));
+
__cxa_exception *except = static_cast<__cxa_exception*>( thrown_exception ) - 1;
+ except->unexpectedHandler = 0;
+ except->terminateHandler = 0;
except->exceptionType = tinfo;
except->exceptionDestructor = dest;
memcpy(&except->unwindHeader.exception_class, "Ac20C++\0", 8);
- uncaught_exception_top ++;
+ __cxa_get_globals()->uncaughtExceptions ++;
_Unwind_RaiseException(thrown_exception);
+ ::_SysDebug("__cxa_throw(%p,%s) :: UNCAUGHT", thrown_exception, tinfo->name());
::std::terminate();
}
extern "C" void *__cxa_begin_catch(void *exceptionObject)
{
+ ::_SysDebug("__cxa_begin_catch(%p)", exceptionObject);
__cxa_exception *except = static_cast<__cxa_exception*>( exceptionObject ) - 1;
except->handlerCount ++;
- except->nextException = uncaught_exception_top;
- uncaught_exception_top = except;
+ except->nextException = __cxa_get_globals()->caughtExceptions;
+ __cxa_get_globals()->caughtExceptions = except;
- uncaught_exception_count --;
+ __cxa_get_globals_fast()->uncaughtExceptions --;
return except;
}
extern "C" void __cxa_end_catch()
{
- struct __cxa_exception *except = uncaught_exception_top;
+ struct __cxa_exception *except = __cxa_get_globals()->caughtExceptions;
+ ::_SysDebug("__cxa_end_catch - %p", except);
except->handlerCount --;
- uncaught_exception_top = except->nextException;
+ __cxa_get_globals()->caughtExceptions = except->nextException;
if( except->handlerCount == 0 ) {
__cxa_free_exception(except+1);
{
std::type_info* exceptionType;
void (*exceptionDestructor)(void *);
- unexpected_handler unexpectedHandler;
- terminate_handler terminateHandler;
+ unexpected_handler* unexpectedHandler;
+ terminate_handler* terminateHandler;
__cxa_exception* nextException;
int handlerCount;
void ::std::terminate()
{
+ _SysDebug("::std::terminate()");
_exit(0);
}
logic_error(what_str)
{
}
+
+::std::length_error::length_error(const ::std::string& what_str):
+ logic_error(what_str)
+{
+}
--- /dev/null
+
+#ifndef _LIBCXX__LIBCXX_HELEPRS_H_
+#define _LIBCXX__LIBCXX_HELEPRS_H_
+
+#if __cplusplus > 199711L // C++11 check
+# define _CXX11_AVAIL 1
+#else
+# define _CXX11_AVAIL 0
+#endif
+
+#endif
+
#ifndef _LIBCXX_ALLOCATOR_
#define _LIBCXX_ALLOCATOR_
+#include "_libcxx_helpers.h"
+
#include "new"
#include "cstddef"
+#include "utility"
namespace std {
new ((void*)p) value_type (val);
}
// C++11
- //template<class U, class... Args>
- //void construct( U* p, Args&&... args ) {
- // ::new ((void*)p) U (forward<Args>(args));
- //}
+ #if _CXX11_AVAIL
+ template<class U, class... Args>
+ void construct( U* p, Args&&... args ) {
+ ::new ((void*)p) U (::std::forward<Args>(args)...);
+ }
+ #endif
void destroy(pointer p) {
p->~value_type();
}
--- /dev/null
+/*
+ */
+#ifndef _LIBCXX_ITERATOR_
+#define _LIBCXX_ITERATOR_
+
+namespace std {
+
+struct input_iterator_tag {};
+struct output_iterator_tag {};
+struct forward_iterator_tag {};
+struct bidrectional_iterator_tag {};
+struct random_access_iterator_tag {};
+
+template <class Category, class T, class Distance = ptrdiff_t, class Pointer = T*, class Reference = T&>
+class iterator
+{
+public:
+ typedef T value_type;
+ typedef Distance difference_type;
+ typedef Pointer pointer_type;
+ typedef Reference reference;
+ typedef Category iterator_category;
+};
+
+template <class Iterator> class iterator_traits;
+template <class T> class iterator_traits<T*>;
+template <class T> class iterator_traits<const T*>;
+
+
+}; // namespace std
+
+#endif
+
+// vim: ft=cpp
+
#include <cstddef>
#include "allocator"
+#include "stdexcept"
+#include "utility"
namespace std {
namespace _bits {
-template <class T,class Alloc> class list_iterator;
+template <class ListType, class T> class list_iterator;
template <class T> class list_item;
}
{
typedef ::std::_bits::list_item<T> item_type;
typedef ::std::_bits::list_item<const T> const_item_type;
- friend class ::std::_bits::list_iterator<item_type,Alloc>;
+ friend class ::std::_bits::list_iterator<list, T>;
typedef typename Alloc::template rebind<item_type>::other item_allocator;
public:
typedef typename allocator_type::const_reference const_reference;
typedef typename allocator_type::pointer pointer;
typedef typename allocator_type::const_pointer const_pointer;
- typedef _bits::list_iterator<T,Alloc> iterator;
- typedef _bits::list_iterator<const T,Alloc> const_iterator;
+ typedef _bits::list_iterator<list,T> iterator;
+ typedef _bits::list_iterator<list,const T> const_iterator;
typedef int difference_type;
typedef size_t size_type;
allocator_type m_allocator;
item_type *m_start;
item_type *m_end;
+ size_type m_item_count;
public:
list(const allocator_type& alloc = allocator_type()):
list& operator =(const list& x);
iterator begin() {
- return iterator(m_start);
+ return iterator(*this, m_start);
}
const_iterator begin() const {
- return const_iterator(m_start);
+ return const_iterator(*this, m_start);
}
iterator end() {
- return iterator(0);
+ return iterator(*this, 0);
}
const_iterator end() const {
- return const_iterator(0);
+ return const_iterator(*this, 0);
}
bool empty() const {
return !m_start;
}
- size_t size() const;
- size_t max_size() const;
+ size_t size() const {
+ return m_item_count;
+ }
+ size_t max_size() const {
+ return (size_type)-1 / sizeof(item_type);
+ }
- T& front();
- const T& front() const;
- T& back();
- const T& back() const;
+ T& front() {
+ return m_start->value;
+ }
+ const T& front() const {
+ return m_start->value;
+ }
+ T& back() {
+ return m_end->value;
+ }
+ const T& back() const {
+ return m_end->value;
+ }
void assign(size_type n, const value_type& val) {
clear();
erase(end());
}
+ template <class... Args>
+ iterator emplace(iterator position, Args&&... args) {
+ item_type *newi = m_item_allocator.allocate(1);
+ m_allocator.construct(&newi->value, ::std::forward<Args>(args)...);
+ return insert_item(position, newi);
+ }
+
iterator insert(iterator position, const value_type& val) {
item_type *newi = m_item_allocator.allocate(1);
m_allocator.construct(&newi->value, val);
- if( position == end() ) {
- newi->next = 0;
- newi->prev = m_end;
- m_end->next = newi;
- m_end = newi;
- }
- else if( position == begin() ) {
- newi->next = m_start;
- newi->prev = 0;
- m_start->prev = newi;
- m_start = newi;
- }
- else {
- newi->prev = position.cur->prev;
- newi->next = position.cur;
- position.cur->prev->next = newi;
- position.cur->prev = newi;
- }
- return ++position;
+ return insert_item(position, newi);
}
void insert(iterator position, size_type n, const value_type& val) {
for( size_type i = 0; i < n; i ++ )
if( position == end() ) {
}
else {
- item_type *oldi = position.cur;
- position ++;
+ item_type *oldi = position.m_cur;
+ ++ position;
if(oldi->prev)
oldi->prev->next = oldi->next;
oldi->next->prev = oldi->prev;
else
m_end = oldi->prev;
-
+
+ m_item_count --;
m_allocator.destroy(&oldi->value);
m_item_allocator.deallocate(oldi, 1);
}
m_start = m_start->next;
delete item;
}
+ m_item_count = 0;
+ }
+private:
+ iterator insert_item(iterator position, item_type *newi) {
+ m_item_count ++;
+ if( m_start == 0 ) {
+ newi->next = 0;
+ newi->prev = m_end;
+ m_start = newi;
+ m_end = newi;
+ return end();
+ }
+ if( position == end() ) {
+ newi->next = 0;
+ newi->prev = m_end;
+ //assert(m_end);
+ m_end->next = newi;
+ m_end = newi;
+ }
+ else if( position == begin() ) {
+ newi->next = m_start;
+ newi->prev = 0;
+ //assert(m_start);
+ m_start->prev = newi;
+ m_start = newi;
+ }
+ else {
+ newi->prev = position.m_cur->prev;
+ newi->next = position.m_cur;
+ position.m_cur->prev->next = newi;
+ position.m_cur->prev = newi;
+ }
+ return ++position;
}
};
value_type value;
};
-template <class T, class Alloc>
+template <class ListType, class T>
class list_iterator//:
//public bidirectional_iterator_tag;
{
- list_item<T> *cur;
- friend class ::std::list<T, Alloc>;
+ const ListType* m_list;
+ list_item<T> *m_cur;
+ friend ListType;
public:
+ list_iterator(const list_iterator& x):
+ m_list(x.m_list),
+ m_cur (x.m_cur)
+ {
+ }
+ list_iterator& operator=(const list_iterator& x) {
+ m_list = x.m_list;
+ m_cur = x.m_cur;
+ }
+
bool operator == (const list_iterator& other) const {
- return cur == other.cur;
+ return m_cur == other.m_cur;
}
bool operator != (const list_iterator& other) const {
- return cur != other.cur;
+ return !(*this == other);
}
T& operator * () {
- return cur->value;
+ return m_cur->value;
}
T& operator -> () {
- return cur->value;
+ return m_cur->value;
}
list_iterator& operator ++ () {
- cur = cur->next;
+ if(!m_cur)
+ throw ::std::logic_error("list iterator ++ on end");
+ m_cur = m_cur->next;
return *this;
}
list_iterator& operator -- () {
- cur = cur->prev;
+ if( m_cur == m_list->m_start )
+ throw ::std::logic_error("list iterator -- on start");
+ if(!m_cur)
+ m_cur = m_list->m_end;
+ else
+ m_cur = m_cur->prev;
return *this;
}
-
+
private:
- list_iterator(list_item<T> *item):
- cur(item)
+ list_iterator(const ListType& list, list_item<T> *item):
+ m_list(&list),
+ m_cur(item)
{
}
};
explicit out_of_range(const string& what_arg);
};
+class length_error:
+ public logic_error
+{
+public:
+ explicit length_error(const string& what_arg);
+};
+
}; // namespace std
#endif
#ifndef _LIBCXX_SYSTEM_ERROR_
#define _LIBCXX_SYSTEM_ERROR_
-#if __cplusplus <= 199711L // C++11 check
+#include "_libcxx_helpers.h"
+
+#if !_CXX11_AVAIL
# error "This header requires C++11 support enabled"
#endif
class error_condition;
class error_code;
-bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept;
-bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept;
-bool operator< (const error_condition& lhs, const error_condition& rhs) noexcept;
-bool operator==(const error_condition& lhs, const error_code& rhs) noexcept;
-bool operator==(const error_code& lhs, const error_condition& rhs) noexcept;
-bool operator!=(const error_condition& lhs, const error_code& rhs) noexcept;
-bool operator!=(const error_code& lhs, const error_condition& rhs) noexcept;
+static bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept;
+static bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept;
+static bool operator< (const error_condition& lhs, const error_condition& rhs) noexcept;
+static bool operator==(const error_condition& lhs, const error_code& rhs) noexcept;
+static bool operator==(const error_code& lhs, const error_condition& rhs) noexcept;
+static bool operator!=(const error_condition& lhs, const error_code& rhs) noexcept;
+static bool operator!=(const error_code& lhs, const error_condition& rhs) noexcept;
extern const error_category& generic_category() noexcept;
extern const error_category& system_category() noexcept;
const char* what() const noexcept;
};
-bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept {
+static inline bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept {
return lhs.category() == rhs.category() && lhs.value() == rhs.value();
}
-bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept {
+static inline bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept {
return !(lhs == rhs);
}
-bool operator< (const error_condition& lhs, const error_condition& rhs) noexcept {
+static inline bool operator< (const error_condition& lhs, const error_condition& rhs) noexcept {
return lhs.category() < rhs.category() || lhs.value() < rhs.value();
}
-bool operator==(const error_condition& lhs, const error_code& rhs) noexcept {
+static inline bool operator==(const error_condition& lhs, const error_code& rhs) noexcept {
return lhs.category().equivalent(rhs, lhs.value()) || rhs.category().equivalent(rhs.value(), lhs);
}
-bool operator==(const error_code& lhs, const error_condition& rhs) noexcept {
+static inline bool operator==(const error_code& lhs, const error_condition& rhs) noexcept {
return lhs.category().equivalent(lhs.value(),rhs) || rhs.category().equivalent(lhs,rhs.value());
}
-bool operator!=(const error_condition& lhs, const error_code& rhs) noexcept {
+static inline bool operator!=(const error_condition& lhs, const error_code& rhs) noexcept {
return !(lhs == rhs);
}
-bool operator!=(const error_code& lhs, const error_condition& rhs) noexcept {
+static inline bool operator!=(const error_code& lhs, const error_condition& rhs) noexcept {
return !(lhs == rhs);
}
--- /dev/null
+/*
+ * Acess2 C++ Library
+ * - By John Hodge (thePowersGang)
+ *
+ * type_traits (header)
+ * - C++11 type traits
+ */
+#ifndef _LIBCXX_TYPE_TRAITS_
+#define _LIBCXX_TYPE_TRAITS_
+
+#include "_libcxx_helpers.h"
+
+#if !_CXX11_AVAIL
+# error "This header requires C++11 support enabled"
+#endif
+
+template <class T> struct remove_reference { typedef T type; };
+template <class T> struct remove_reference<T&> { typedef T type; };
+template <class T> struct remove_reference<T&&> { typedef T type; };
+
+#endif
+
+// vim: ft=cpp
+
#ifndef _LIBCXX_UTILITY_
#define _LIBCXX_UTILITY_
+#include "_libcxx_helpers.h"
+#include "type_traits"
+
namespace std {
template <class T1, class T2>
return !(lhs == rhs);
}
+#if _CXX11_AVAIL
+template <class T>
+T&& forward(typename remove_reference<T>::type& arg) noexcept {
+ return static_cast<decltype(arg)&&>(arg);
+}
+template <class T>
+T&& forward(typename remove_reference<T>::type&& arg) noexcept {
+ return static_cast<decltype(arg)&&>(arg);
+}
+#endif
+
}; // namespace std
#endif
#define _LIBCXX_VECTOR_
#include <allocator>
+#include <stdexcept>
+
+extern "C" void _SysDebug(const char *, ...);
namespace std {
return *this;
}
bool operator==(const vector_iterator& other) const {
- return m_array == other.m_array && m_pos == other.m_pos;
+ return m_pos == other.m_pos;
}
bool operator!=(const vector_iterator& other) const {
return !(*this == other);
vector(size_type n, const value_type& val = value_type(), const allocator_type& alloc = allocator_type()):
vector(alloc)
{
-
+ resize(n, val);
}
vector(const vector& x):
vector(x.m_alloc)
return m_size == 0;
}
void reserve(size_type n) {
- //if( n > max_size() )
- // throw ::std::length_error();
+ if( n > max_size() )
+ throw ::std::length_error("::std::vector::reserve");
+ if( n > m_capacity )
+ {
+ size_type size = (n + 0x1F) & ~0x1F;
+ auto new_area = m_alloc.allocate(size);
+ for( size_type i = 0; i < m_size; i ++ )
+ new_area[i] = m_data[i];
+ m_alloc.deallocate(m_data, m_capacity);
+ m_data = new_area;
+ m_capacity = size;
+ //::_SysDebug("::std::vector::resize - m_capacity=%i for n=%i", m_capacity, n);
+ }
}
void shrink_to_fit() {
}
extern "C" int SoMain()
{
+ //extern void _init();
+ //_init();
// nope
return 0;
}
*/
#include <stddef.h>
#include <stdlib.h>
+#include <acess/sys.h>
// === CODE ===
void *operator new( size_t size )
{
+ //_SysDebug("libc++ - operator new(%i)", size);
return malloc( size );
}
void *operator new( size_t size, void* ptr )
{
+ //_SysDebug("libc++ - operator new(%i, %p)", size, ptr);
size = size;
return ptr;
}
void *operator new[]( size_t size )
{
+ //_SysDebug("libc++ - operator new[](%i)", size);
return malloc( size );
}
void *operator new[]( size_t size, void* ptr )
{
+ //_SysDebug("libc++ - operator new[](%i, %p)", size, ptr);
size = size;
return ptr;
}
* - typeid and dynamic_cast
*/
#include <typeinfo>
+#include <acess/sys.h>
namespace std {
bool type_info::operator==(const type_info& other) const
{
+ _SysDebug("type_info::operator== - '%s' == '%s'", this->__type_name, other.__type_name);
return this->__type_name == other.__type_name;
}
bool type_info::operator!=(const type_info& other) const
{
+ _SysDebug("type_info::operator!= - '%s' != '%s'", this->__type_name, other.__type_name);
return this->__type_name != other.__type_name;
}
bool type_info::before(const type_info& other) const
{
+ _SysDebug("type_info::before - '%s' < '%s'", this->__type_name, other.__type_name);
return this->__type_name < other.__type_name;
}
}; // namespace std
-