From 7428fa7e597ed11db791ab96bc3c03bda178ed5c Mon Sep 17 00:00:00 2001 From: Brett Date: Mon, 3 Jun 2024 02:29:51 -0400 Subject: [PATCH] gwfsdf --- CMakeLists.txt | 6 +- examples/main.cpp | 15 +++++ include/blt/gp/program.h | 142 ++++++++++++++++++++++++++++++++++----- lib/blt | 2 +- 4 files changed, 143 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 255cb20..e09c673 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.25) -project(blt-gp VERSION 0.0.5) +project(blt-gp VERSION 0.0.6) option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF) option(ENABLE_UBSAN "Enable the ub sanitizer" OFF) @@ -42,8 +42,8 @@ if (${BUILD_EXAMPLES}) target_link_libraries(blt-gp-example PUBLIC BLT blt-gp) - target_compile_options(blt-gp-example PRIVATE -Wall -Wextra -Werror -Wpedantic -Wno-comment) - target_link_options(blt-gp-example PRIVATE -Wall -Wextra -Werror -Wpedantic -Wno-comment) + target_compile_options(blt-gp-example PRIVATE -Wall -Wextra -Wpedantic -Wno-comment) + target_link_options(blt-gp-example PRIVATE -Wall -Wextra -Wpedantic -Wno-comment) if (${ENABLE_ADDRSAN} MATCHES ON) target_compile_options(blt-gp-example PRIVATE -fsanitize=address) diff --git a/examples/main.cpp b/examples/main.cpp index 639b0dd..56da706 100644 --- a/examples/main.cpp +++ b/examples/main.cpp @@ -16,8 +16,23 @@ * along with this program. If not, see . */ #include +#include int main() { + blt::gp::operation silly([](float f, int i, bool b) -> float { + return static_cast(b); + }); + + float f = 10.5; + int i = 412; + bool b = true; + + std::array arr{reinterpret_cast(&f), reinterpret_cast(&i), reinterpret_cast(&b)}; + + blt::span spv{arr}; + + std::cout << silly.operator()(spv) << std::endl; + std::cout << "Hello World!" << std::endl; } \ No newline at end of file diff --git a/include/blt/gp/program.h b/include/blt/gp/program.h index de1b584..9d98755 100644 --- a/include/blt/gp/program.h +++ b/include/blt/gp/program.h @@ -22,7 +22,12 @@ #include #include #include +#include +#include #include +#include +#include +#include namespace blt::gp { @@ -30,6 +35,95 @@ namespace blt::gp { }; + class type + { + public: + template + static type make_type(blt::size_t id) + { + return type(sizeof(T), id, blt::type_string()); + } + + [[nodiscard]] blt::size_t size() const + { + return size_; + } + + [[nodiscard]] blt::size_t id() const + { + return id_; + } + + [[nodiscard]] std::string_view name() const + { + return name_; + } + + private: + type(size_t size, size_t id, std::string_view name): size_(size), id_(id), name_(name) + {} + + blt::size_t size_; + blt::size_t id_; + std::string name_; + }; + + class type_system + { + public: + type_system() = default; + + template + inline type register_type() + { + types.push_back(type::make_type(types.size())); + return types.back(); + } + + private: + std::vector types; + }; + + class stack_allocator + { + constexpr static blt::size_t BLOCK_SIZE = 4096; + public: + + private: + template + static inline auto to_block(T* p) + { + return reinterpret_cast(reinterpret_cast(p) & static_cast(~(BLOCK_SIZE - 1))); + } + + struct block + { + struct block_metadata_t + { + block* next = nullptr; + block* prev = nullptr; + blt::u8* offset = nullptr; + } metadata; + blt::u8 buffer[BLOCK_SIZE - sizeof(block_metadata_t)]{}; + + block() + { + metadata.offset = buffer; + } + + // remaining space inside the block after accounting for the metadata + static constexpr blt::size_t BLOCK_REMAINDER = BLOCK_SIZE - sizeof(typename block::block_metadata_t); + }; + + static block* allocate_block() + { + return reinterpret_cast(std::aligned_alloc(BLOCK_SIZE, BLOCK_SIZE)); + } + + private: + block* head = nullptr; + }; + template class operation { @@ -40,18 +134,16 @@ namespace blt::gp operation(operation&& move) = default; - template + template, void>> + explicit operation(const T& functor): func(functor) + {} + + template, void>> explicit operation(const T& functor) { - if constexpr (std::is_same_v) - { - func = functor; - } else - { - func = [&functor](Args... args) { - return functor(args...); - }; - } + func = [&functor](Args... args) { + return functor(args...); + }; } explicit operation(function_t&& functor): func(std::move(functor)) @@ -62,21 +154,35 @@ namespace blt::gp return func(args...); } - inline Return operator()(blt::span args) + Return operator()(blt::span args) { - + auto pack_sequence = std::make_integer_sequence(); + return function_evaluator(args, pack_sequence); + } + + std::function)> to_functor() + { + return [this](blt::span args) { + return this->operator()(args); + }; } private: + template + static inline T& access_pack_index(blt::span args) + { + return *reinterpret_cast(args[index]); + } + + template + Return function_evaluator(blt::span args, std::integer_sequence) + { + return func(access_pack_index(args)...); + } + function_t func; }; - template - class operations - { - - }; - } diff --git a/lib/blt b/lib/blt index a8b2bc2..bc68e6d 160000 --- a/lib/blt +++ b/lib/blt @@ -1 +1 @@ -Subproject commit a8b2bc2d010480544c3162daa7384a252946bda1 +Subproject commit bc68e6dd4a3dfa1de9be2fb8e9302b52c4f3db5c