discard
parent
5ffb89af93
commit
8af186cd8e
|
@ -9,6 +9,7 @@ if(!MSVC)
|
||||||
add_compile_options(-march=native)
|
add_compile_options(-march=native)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
|
||||||
add_subdirectory(libs/BLT)
|
add_subdirectory(libs/BLT)
|
||||||
|
|
2
libs/BLT
2
libs/BLT
|
@ -1 +1 @@
|
||||||
Subproject commit 89bde7c6e85ab50de988fb3f7b91d2041b41a4cb
|
Subproject commit ffa20e0e51a8b308458e0b3ca2946af4eef4bae6
|
|
@ -21,10 +21,19 @@
|
||||||
#include <blt/std/vector.h>
|
#include <blt/std/vector.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "blt/std/utility.h"
|
#include "blt/std/utility.h"
|
||||||
|
#include "blt/std/hashmap.h"
|
||||||
#include <blt/std/ranges.h>
|
#include <blt/std/ranges.h>
|
||||||
|
#include <utility>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
auto run_once()
|
||||||
|
{
|
||||||
|
static auto called = false;
|
||||||
|
return !std::exchange(called, true);
|
||||||
|
};
|
||||||
|
|
||||||
namespace fb
|
namespace fb
|
||||||
{
|
{
|
||||||
using arg_t = double;
|
using arg_t = double;
|
||||||
|
@ -144,14 +153,12 @@ namespace fb
|
||||||
class arg_constraint_container
|
class arg_constraint_container
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
blt::vector<std::vector<ENUM_TYPE>> map;
|
blt::vector<blt::vector<ENUM_TYPE>> map;
|
||||||
public:
|
public:
|
||||||
template<typename T, std::enable_if<std::is_convertible_v<T, blt::vector<std::vector<ENUM_TYPE>>>, bool> = true>
|
constexpr explicit arg_constraint_container(const blt::vector<blt::vector<ENUM_TYPE>>& map): map(map)
|
||||||
constexpr explicit arg_constraint_container(T&& map): map(std::forward<T>(map))
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template<typename T, std::enable_if<std::is_convertible_v<T, blt::vector<ENUM_TYPE>>, bool> = true>
|
constexpr explicit arg_constraint_container(blt::size_t argc, const blt::vector<ENUM_TYPE>& map)
|
||||||
constexpr explicit arg_constraint_container(blt::size_t argc, T&& map)
|
|
||||||
{
|
{
|
||||||
for (blt::size_t i = 0; i < argc; i++)
|
for (blt::size_t i = 0; i < argc; i++)
|
||||||
this->map.push_back(map);
|
this->map.push_back(map);
|
||||||
|
@ -162,36 +169,83 @@ namespace fb
|
||||||
for (const auto& v : maps)
|
for (const auto& v : maps)
|
||||||
this->map.push_back(v);
|
this->map.push_back(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr const blt::vector<ENUM_TYPE>& getAllowedArguments(blt::size_t arg) const
|
||||||
|
{
|
||||||
|
return map[arg];
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename ARG_TYPE, typename ENUM_TYPE>
|
template<typename ARG_TYPE, typename ENUM_TYPE>
|
||||||
class operator_t
|
class operator_t
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
ENUM_TYPE our_type;
|
||||||
arg_count_t argc;
|
arg_count_t argc;
|
||||||
std::function<ARG_TYPE(blt::span<ARG_TYPE>)> func;
|
std::function<ARG_TYPE(blt::span<ARG_TYPE>)> func;
|
||||||
arg_constraint_container<ENUM_TYPE> allowed_inputs;
|
arg_constraint_container<ENUM_TYPE> allowed_inputs;
|
||||||
public:
|
|
||||||
constexpr operator_t(arg_count_t argc, std::function<ARG_TYPE(blt::span<ARG_TYPE>)> func): argc(argc), func(std::move(func))
|
constexpr operator_t(ENUM_TYPE type, arg_count_t argc, std::function<ARG_TYPE(blt::span<ARG_TYPE>)> func,
|
||||||
|
arg_constraint_container<ENUM_TYPE> allowed_inputs):
|
||||||
|
our_type(type), argc(argc), func(std::move(func)), allowed_inputs(std::move(allowed_inputs))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
public:
|
||||||
|
static constexpr operator_t make_operator(ENUM_TYPE type, arg_count_t argc,
|
||||||
|
std::function<ARG_TYPE(blt::span<ARG_TYPE>)> func,
|
||||||
|
arg_constraint_container<ENUM_TYPE> allowed_inputs)
|
||||||
|
{
|
||||||
|
return operator_t{type, argc, func, allowed_inputs};
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr arg_count_t argCount() const
|
[[nodiscard]] constexpr arg_count_t argCount() const
|
||||||
{ return argc; }
|
{ return argc; }
|
||||||
|
|
||||||
[[nodiscard]] constexpr std::function<ARG_TYPE(blt::span<ARG_TYPE>)> function() const
|
[[nodiscard]] constexpr std::function<ARG_TYPE(blt::span<ARG_TYPE>)>& function() const
|
||||||
{ return func; }
|
{ return func; }
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr const blt::vector<ENUM_TYPE>& getAllowedArguments(blt::size_t arg) const
|
||||||
|
{ return allowed_inputs.getAllowedArguments(arg); }
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr ENUM_TYPE type() const
|
||||||
|
{ return our_type; }
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename NODE_CONTAINER, typename ALLOC>
|
template<typename ARG_TYPE, typename ENUM_TYPE>
|
||||||
|
struct operator_container_constructor_t;
|
||||||
|
|
||||||
|
template<typename ARG_TYPE, typename ENUM_TYPE, blt::i32 ENUM_MAX>
|
||||||
|
struct operator_container_t
|
||||||
|
{
|
||||||
|
friend operator_container_constructor_t<ARG_TYPE, ENUM_TYPE>;
|
||||||
|
private:
|
||||||
|
constexpr operator_container_t(std::initializer_list<std::pair<ENUM_TYPE, operator_t<ARG_TYPE, ENUM_TYPE>>> list)
|
||||||
|
{
|
||||||
|
for (const auto& v : list)
|
||||||
|
{
|
||||||
|
operators[static_cast<blt::i32>(v.first)] = v.second;
|
||||||
|
max_argc = std::max(v.second.argCount(), max_argc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
arg_count_t max_argc;
|
||||||
|
std::array<operator_t<ARG_TYPE, ENUM_TYPE>, ENUM_MAX> operators;
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr arg_count_t getMaxArgc() const
|
||||||
|
{
|
||||||
|
return max_argc;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename NODE_CONTAINER, arg_count_t MAX_ARGS, template<typename> typename ALLOC>
|
||||||
class node_tree
|
class node_tree
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
static ALLOC allocator;
|
static ALLOC<NODE_CONTAINER> allocator;
|
||||||
struct node
|
struct node
|
||||||
{
|
{
|
||||||
std::array<node*, NODE_CONTAINER::determine_max_argc()> children;
|
std::array<node*, MAX_ARGS> children;
|
||||||
NODE_CONTAINER caller;
|
NODE_CONTAINER caller;
|
||||||
};
|
};
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in New Issue