Browse Source

Compiles with GCC

tagfs
Ludovic 'Archivist' Lagouardette 3 years ago
parent
commit
1dbc473bbe
13 changed files with 108 additions and 87 deletions
  1. +3
    -1
      .vscode/settings.json
  2. +5
    -4
      Makefile
  3. +1
    -3
      include/gp/allocator/aggregator.hpp
  4. +3
    -1
      include/gp/allocator/buddy.hpp
  5. +6
    -8
      include/gp/array.hpp
  6. +7
    -7
      include/gp/bitops.hpp
  7. +14
    -0
      include/gp/concepts.hpp
  8. +2
    -2
      include/gp/math/integer_math.hpp
  9. +15
    -27
      include/gp/optional.hpp
  10. +33
    -27
      include/gp/pair.hpp
  11. +7
    -1
      include/gp/range.hpp
  12. +10
    -6
      include/gp/ring_list.hpp
  13. +2
    -0
      tests.cpp

+ 3
- 1
.vscode/settings.json View File

@ -4,7 +4,9 @@
"-I${workspaceRoot}/include" "-I${workspaceRoot}/include"
], ],
"clang.cxxflags": [ "clang.cxxflags": [
"-std=c++17",
"-std=c++20",
"-Wall",
"-pedantic",
"-I${workspaceRoot}/include" "-I${workspaceRoot}/include"
] ]
} }

+ 5
- 4
Makefile View File

@ -1,7 +1,8 @@
CXX= clang++-10
CXXFLAGS= --std=c++17 -O0 -pthread -DGP_TESTS -DFUZZ_STRENGTH=500 -DNO_BENCH=0 -pedantic -Werror \
-Wno-unknown-attributes -frtti \
-g -fprofile-instr-generate -fcoverage-mapping \
CXX= g++
CXXFLAGS= --std=c++20 -O0 -g -pthread -DGP_TESTS -DFUZZ_STRENGTH=500 -DNO_BENCH=0 -pedantic \
-frtti \
#-g -fprofile-instr-generate -fcoverage-mapping -Wno-unknown-attributes \
-fsanitize=address -fno-omit-frame-pointer -fsanitize=address -fno-omit-frame-pointer
all: tests all: tests

+ 1
- 3
include/gp/allocator/aggregator.hpp View File

@ -35,7 +35,7 @@ namespace gp {
return internal_representation.try_reallocate(ptr, sz); return internal_representation.try_reallocate(ptr, sz);
} }
}; };
using local_container = ring_list<virtual_allocator, aggregator, false>;
using local_container = ring_list<virtual_allocator, aggregator, falsep">, true>;
local_container contents; local_container contents;
local_container::explorer mark; local_container::explorer mark;
@ -99,6 +99,4 @@ namespace gp {
return false; return false;
} }
}; };
} }

+ 3
- 1
include/gp/allocator/buddy.hpp View File

@ -52,6 +52,8 @@ namespace gp{
**/ **/
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wreturn-type" #pragma clang diagnostic ignored "-Wreturn-type"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wreturn-type"
twig get_twig(size_t idx) const { twig get_twig(size_t idx) const {
auto far = idx / 4; auto far = idx / 4;
auto local = idx % 4; auto local = idx % 4;
@ -66,6 +68,7 @@ namespace gp{
return stack[far].d; return stack[far].d;
} }
} }
#pragma GCC diagnostic pop
#pragma clang diagnostic pop #pragma clang diagnostic pop
void set_twig(size_t idx, twig v) { void set_twig(size_t idx, twig v) {
@ -288,7 +291,6 @@ namespace gp{
auto r = get_twig(get_right(idx)); auto r = get_twig(get_right(idx));
set_twig(idx, 2*(l.used | l.used_children | r.used | r.used_children)); set_twig(idx, 2*(l.used | l.used_children | r.used | r.used_children));
}); });
return true; return true;

+ 6
- 8
include/gp/array.hpp View File

@ -39,19 +39,17 @@ namespace gp{
); );
} }
template<>
array<T[sz]>(T (& oth)[sz]) {
array(T (& oth)[sz]) {
gp::move_uninitialized<T>( gp::move_uninitialized<T>(
gp::nameless_range(oth, oth+sz),
gp::nameless_range(begin(), end())
gp::nameless_rangeo"><int*>(oth, oth+sz),
gp::nameless_rangeo"><associated_iterator>(begin(), end())
); );
} }
template<>
array<T[sz]>(T (&& oth)[sz]) {
array(T (&& oth)[sz]) {
gp::move_uninitialized( gp::move_uninitialized(
gp::nameless_range(oth, oth+sz),
gp::nameless_range(begin(), end())
gp::nameless_rangeo"><int*>((T*)oth, (T*)oth+sz),
gp::nameless_rangeo"><associated_iterator>(begin(), end())
); );
} }

+ 7
- 7
include/gp/bitops.hpp View File

@ -8,6 +8,10 @@ namespace gp{
constexpr uint8_t magic_ = (const uint8_t&)uint32_; constexpr uint8_t magic_ = (const uint8_t&)uint32_;
} }
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wfour-char-constants"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmultichar"
enum class endian : uint16_t enum class endian : uint16_t
{ {
#ifdef _WIN32 #ifdef _WIN32
@ -21,15 +25,11 @@ namespace gp{
#else #else
little = true, little = true,
big = false, big = false,
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wfour-char-constants"
#pragma gcc diagnostic push
#pragma gcc diagnostic ignored "-Wfour-char-constants"
native = ('ABCD'==0x41424344UL) native = ('ABCD'==0x41424344UL)
#pragma gcc diagnostic pop
#pragma clang diagnostic pop
#endif
}; };
#endif
#pragma GCC diagnostic pop
#pragma clang diagnostic pop
template <typename T> template <typename T>

+ 14
- 0
include/gp/concepts.hpp View File

@ -0,0 +1,14 @@
#pragma once
#include <concepts>
template<typename T>
concept ForwardIteratorLike = requires(T a) {
{++a} -> auto;
{*a} -> auto;
};
template<typename T>
concept RangeLike = requires(T a) {
{a.begin()} -> ForwardIteratorLike;
{a.end()} -> ForwardIteratorLike;
};

+ 2
- 2
include/gp/math/integer_math.hpp View File

@ -17,8 +17,8 @@ namespace gp {
{ {
constexpr int MultiplyDeBruijnBitPosition[32] = constexpr int MultiplyDeBruijnBitPosition[32] =
{ {
0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30,
8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31
0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30,
8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31
}; };
v |= v >> 1; v |= v >> 1;

+ 15
- 27
include/gp/optional.hpp View File

@ -161,6 +161,21 @@ namespace gp{
return *this; return *this;
} }
optional& operator=(optional&& value){
if(ready) {
delete ptr; // TODO: Use allocators
}
if(value.ready) {
ptr = value.ptr;
value.ready = false;
ready = true;
return *this;
} else {
ready = false;
return *this;
}
}
template<typename U> template<typename U>
optional& operator=(U&& value) { optional& operator=(U&& value) {
if(ready) { if(ready) {
@ -177,33 +192,6 @@ namespace gp{
return *this; return *this;
} }
template<>
optional& operator=<optional>(optional& value) {
if(ready) {
*ptr = value;
} else {
ready = true;
ptr = new optional(value.value()); // TODO: Use allocators
}
return *this;
}
template<>
optional& operator=<optional>(optional&& value){
if(ready) {
delete ptr; // TODO: Use allocators
}
if(value.ready) {
ptr = value.ptr;
value.ready = false;
ready = true;
return *this;
} else {
ready = false;
return *this;
}
}
operator T&() { operator T&() {
gp_config::assertion(ready, "bad optional access"); gp_config::assertion(ready, "bad optional access");
return *ptr; return *ptr;

+ 33
- 27
include/gp/pair.hpp View File

@ -34,39 +34,45 @@ namespace gp{
second = gp::move(v.second); second = gp::move(v.second);
return *this; return *this;
} }
};
bool operator==(const pair& rhs) {
return first == rhs.first and second == rhs.second;
}
template<typename F, typename S>
bool operator==(const pair<F, S>& lhs, const pair<F, S>& rhs) {
return lhs.first == rhs.first and lhs.second == rhs.second;
}
bool operator!=(const pair& rhs) {
return first != rhs.first or second != rhs.second;
}
template<typename F, typename S>
bool operator!=(const pair<F, S>& lhs, const pair<F, S>& rhs) {
return lhs.first != rhs.first or lhs.second != rhs.second;
}
bool operator<=(const pair& rhs) {
if(first > rhs.first) {
return false;
} else if(first == rhs.first) {
return second <= rhs.second;
}
return true;
template<typename F, typename S>
bool operator<=(const pair<F, S>& lhs, const pair<F, S>& rhs) {
if(lhs.first > rhs.first) {
return false;
} else if(lhs.first == rhs.first) {
return lhs.second <= rhs.second;
} }
return true;
}
bool operator>=(const pair& rhs) {
if(first < rhs.first) {
return false;
} else if(first == rhs.first) {
return second >= rhs.second;
}
return true;
template<typename F, typename S>
bool operator>=(const pair<F, S>& lhs, const pair<F, S>& rhs) {
if(lhs.first < rhs.first) {
return false;
} else if(lhs.first == rhs.first) {
return lhs.second >= rhs.second;
} }
return true;
}
bool operator<(const pair& rhs) {
return !(*this >= rhs);
}
template<typename F, typename S>
bool operator<(const pair<F, S>& lhs, const pair<F, S>& rhs) {
return !(lhs >= rhs);
}
bool operator>(const pair& rhs) {
return !(*this <= rhs);
p">}
};
template<typename F, typename S>
bool operator>(const pair<F, S>& lhs, const pair<F, S>& rhs) {
k">return !(lhs <= rhs);
}
} }

+ 7
- 1
include/gp/range.hpp View File

@ -2,7 +2,13 @@
#include "gp/algorithm/tmp_manip.hpp" #include "gp/algorithm/tmp_manip.hpp"
namespace gp{ namespace gp{
template<typename it, bool Enable = std::is_same<typename it::difference_type,std::size_t>::value>
template<typename T>
concept IsSubstractible = requires(T a, T b)
{
{a - b} -> std::integral;
};
template<typename it, bool Enable = IsSubstractible<it>>
class nameless_range; class nameless_range;
template<typename it> template<typename it>

+ 10
- 6
include/gp/ring_list.hpp View File

@ -5,7 +5,7 @@
#include "gp_config.hpp" #include "gp_config.hpp"
namespace gp { namespace gp {
template<typename T, typename allocator, bool copy_allocator = false>
template<typename T, typename allocator, bool copy_allocator = falsep">, bool may_contain_self = false>
class ring_list{ class ring_list{
public: public:
class explorer; class explorer;
@ -20,8 +20,8 @@ namespace gp {
, next{this} , next{this}
{} {}
friend class gp::ring_list<T, allocator, copy_allocator>::explorer;
friend class gp::ring_list<T, allocator, copy_allocator>;
friend class gp::ring_list<T, allocator, copy_allocatorp">, may_contain_self>::explorer;
friend class gp::ring_list<T, allocator, copy_allocatorp">, may_contain_self>;
}; };
class explorer { class explorer {
@ -149,9 +149,13 @@ namespace gp {
gp_config::assertion(used_allocator.deallocate(v), "Bad free of node"); gp_config::assertion(used_allocator.deallocate(v), "Bad free of node");
} }
~ring_list() {
while(any_node) {
remove(explore());
~ring_list()
{
// TODO: Find a less hackish way to resove this issue
if constexpr (!may_contain_self) {
while(any_node) {
remove(explore());
}
} }
} }
}; };

+ 2
- 0
tests.cpp View File

@ -9,6 +9,8 @@
#include "pair_test.cpp" #include "pair_test.cpp"
#include <iostream> #include <iostream>
#include "gp/concepts.hpp"
alignas(2048) gp::array<char, 4096> static_mapper::store; alignas(2048) gp::array<char, 4096> static_mapper::store;
gp::buddy<> static_mapper::impl = gp::buddy<>{store.begin().data, store.size()}; gp::buddy<> static_mapper::impl = gp::buddy<>{store.begin().data, store.size()};

Loading…
Cancel
Save