so progress is slow

thread
Brett 2024-06-24 14:00:08 -04:00
parent cd930419ea
commit 8a9ecb3484
7 changed files with 117 additions and 28 deletions

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.25) cmake_minimum_required(VERSION 3.25)
project(blt-gp VERSION 0.0.28) project(blt-gp VERSION 0.0.29)
option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF) option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF)
option(ENABLE_UBSAN "Enable the ub sanitizer" OFF) option(ENABLE_UBSAN "Enable the ub sanitizer" OFF)

View File

@ -31,7 +31,7 @@ blt::gp::operation_t lit([]() {
return dist(program.get_random()); return dist(program.get_random());
}); });
int main() int main_old()
{ {
type_system.register_type<float>(); type_system.register_type<float>();
type_system.register_type<bool>(); type_system.register_type<bool>();

View File

@ -17,6 +17,7 @@
*/ */
#include <iostream> #include <iostream>
#include <blt/gp/program.h> #include <blt/gp/program.h>
#include <blt/std/logging.h>
#include <variant> #include <variant>
#include <stack> #include <stack>
#include <deque> #include <deque>
@ -300,9 +301,32 @@ struct super_large
unsigned char data[5129]; unsigned char data[5129];
}; };
struct context
{
float x, y;
};
namespace blt::gp::detail
{
class operator_storage_test
{
public:
explicit operator_storage_test(blt::gp::gp_operations<context>& ops): ops(ops)
{}
inline blt::gp::detail::callable_t& operator[](blt::size_t index)
{
return ops.operators[index];
}
private:
blt::gp::gp_operations<context>& ops;
};
}
blt::gp::stack_allocator alloc; blt::gp::stack_allocator alloc;
int main_old() int main()
{ {
constexpr blt::size_t MAX_ALIGNMENT = 8; constexpr blt::size_t MAX_ALIGNMENT = 8;
test(); test();
@ -381,6 +405,43 @@ int main_old()
std::cout << std::endl; std::cout << std::endl;
blt::gp::operation_t silly_op_3([](const context& ctx, float f) {
return ctx.x + ctx.y + f;
});
blt::gp::operation_t silly_op_4([](const context& ctx) {
return ctx.x;
});
blt::gp::type_system system;
system.register_type<float>();
blt::gp::gp_operations<context> ops{system};
//BLT_TRACE(blt::type_string<decltype(silly_op_3)::first::type>());
//BLT_TRACE(typeid(decltype(silly_op_3)::first::type).name());
//BLT_TRACE(blt::type_string<blt::gp::detail::remove_cv_ref<decltype(silly_op_3)::first::type>>());
//BLT_TRACE("Same types? %s", (std::is_same_v<context, blt::gp::detail::remove_cv_ref<decltype(silly_op_3)::first::type>>) ? "true" : "false");
ops.add_operator(silly_op_3);
ops.add_operator(silly_op_4);
ops.add_operator(silly_op_2);
blt::gp::detail::operator_storage_test de(ops);
context hello{5, 10};
alloc.push(1.153f);
de[0](static_cast<void*>(&hello), alloc);
BLT_TRACE("first value: %f", alloc.pop<float>());
de[1](static_cast<void*>(&hello), alloc);
BLT_TRACE("second value: %f", alloc.pop<float>());
alloc.push(1.0f);
alloc.push(52.213f);
de[2](static_cast<void*>(&hello), alloc);
BLT_TRACE("third value: %f", alloc.pop<float>());
//auto* pointer = static_cast<void*>(head->metadata.offset); //auto* pointer = static_cast<void*>(head->metadata.offset);
//return std::align(alignment, bytes, pointer, remaining_bytes); //return std::align(alignment, bytes, pointer, remaining_bytes);

View File

@ -24,13 +24,22 @@ namespace blt::gp
{ {
class gp_program; class gp_program;
class type; class type;
class type_system; class type_system;
class tree_generator_t; class tree_generator_t;
class grow_generator_t; class grow_generator_t;
class full_generator_t; class full_generator_t;
namespace detail
{
class operator_storage_test;
}
} }
#endif //BLT_GP_FWDECL_H #endif //BLT_GP_FWDECL_H

View File

@ -30,6 +30,42 @@ namespace blt::gp
namespace detail namespace detail
{ {
using callable_t = std::function<void(void*, stack_allocator&)>; using callable_t = std::function<void(void*, stack_allocator&)>;
template<typename T>
using remove_cv_ref = std::remove_cv_t<std::remove_reference_t<T>>;
template<typename...>
struct first_arg;
template<typename First, typename... Args>
struct first_arg<First, Args...>
{
using type = First;
};
template<>
struct first_arg<>
{
using type = void;
};
template<bool b, typename... types>
struct is_same;
template<typename... types>
struct is_same<true, types...> : public std::false_type
{
};
template<typename... types>
struct is_same<false, types...> : public std::is_same<types...>
{
};
template<typename... types>
constexpr bool is_same_v = is_same<sizeof...(types) == 0, types...>::value;
struct empty_t struct empty_t
{ {
}; };
@ -66,17 +102,6 @@ namespace blt::gp
} }
}; };
template<typename First, typename... Args>
struct first_arg
{
using type = First;
};
template<>
struct first_arg<void>
{
};
template<typename Return, typename, typename... Args> template<typename Return, typename, typename... Args>
struct call_without_first : public call_with<Return, Args...> struct call_without_first : public call_with<Return, Args...>
{ {
@ -118,7 +143,7 @@ namespace blt::gp
{ {
BLT_ABORT("Cannot pass context to function without arguments!"); BLT_ABORT("Cannot pass context to function without arguments!");
} }
auto& ctx_ref = *static_cast<typename first_arg<Args...>::type*>(context); auto& ctx_ref = *static_cast<detail::remove_cv_ref<typename detail::first_arg<Args...>::type>*>(context);
if constexpr (sizeof...(Args) == 1) if constexpr (sizeof...(Args) == 1)
{ {
return func(ctx_ref); return func(ctx_ref);
@ -132,13 +157,7 @@ namespace blt::gp
[[nodiscard]] detail::callable_t make_callable() const [[nodiscard]] detail::callable_t make_callable() const
{ {
return [this](void* context, stack_allocator& values) { return [this](void* context, stack_allocator& values) {
if constexpr (sizeof...(Args) == 0) if constexpr (detail::is_same_v<Context, detail::remove_cv_ref<typename detail::first_arg<Args...>::type>>)
{
values.push(this->operator()(values));
} else
{
// annoying hack.
if constexpr (std::is_same_v<Context, typename first_arg<Args...>::type>)
{ {
// first arg is context // first arg is context
values.push(this->operator()(context, values)); values.push(this->operator()(context, values));
@ -147,7 +166,6 @@ namespace blt::gp
// first arg isn't context // first arg isn't context
values.push(this->operator()(values)); values.push(this->operator()(values));
} }
}
}; };
} }

View File

@ -50,6 +50,7 @@ namespace blt::gp
class gp_operations class gp_operations
{ {
friend class gp_program; friend class gp_program;
friend class blt::gp::detail::operator_storage_test;
public: public:
explicit gp_operations(type_system& system): system(system) explicit gp_operations(type_system& system): system(system)

@ -1 +1 @@
Subproject commit ac163a34b9d70346df80fcac44054e8dffe9ad43 Subproject commit 2a34be2e7b452aa623b9043b7decf83c2e367cc7