#pragma once /* * Copyright (C) 2024 Brett Terpstra * * This program 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. * * This program 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 this program. If not, see . */ #ifndef BLT_GP_PROGRAM_H #define BLT_GP_PROGRAM_H #include #include #include #include #include #include #include #include #include #include #include #include namespace blt::gp { class identifier { }; 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; }; template class operation; template class operation { public: using function_t = std::function; constexpr operation(const operation& copy) = default; constexpr operation(operation&& move) = default; template constexpr explicit operation(const Functor& functor): func(functor) {} template [[nodiscard]] inline constexpr blt::size_t getByteOffset() const { blt::size_t offset = 0; blt::size_t current_index = 0; ((offset += (current_index++ > index ? stack_allocator::aligned_size() : 0)), ...); return offset; } template inline constexpr Return sequence_to_indices(stack_allocator& allocator, std::integer_sequence) const { // expands Args and indices, providing each argument with its index calculating the current argument byte offset return func(allocator.from(getByteOffset())...); } [[nodiscard]] constexpr inline Return operator()(stack_allocator& allocator) const { constexpr auto seq = std::make_integer_sequence(); Return ret = sequence_to_indices(allocator, seq); allocator.pop_bytes((stack_allocator::aligned_size() + ...)); return ret; } 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 operation(Return (*)(Args...)) -> operation; // // template // operation(std::function) -> operation; // // template // operation(std::function) -> operation; } #endif //BLT_GP_PROGRAM_H