From 96d8b278e89e01436e1320ba73f391f2745afa11 Mon Sep 17 00:00:00 2001 From: Brett Date: Sun, 30 Jun 2024 13:57:45 -0400 Subject: [PATCH] move operator info into a struct for locality --- CMakeLists.txt | 2 +- include/blt/gp/program.h | 12 ++++++++---- include/blt/gp/typesystem.h | 15 ++++++--------- lib/blt | 2 +- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cc244f3..8428a72 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.25) -project(blt-gp VERSION 0.0.43) +project(blt-gp VERSION 0.0.44) include(CTest) diff --git a/include/blt/gp/program.h b/include/blt/gp/program.h index 0b167a4..369e247 100644 --- a/include/blt/gp/program.h +++ b/include/blt/gp/program.h @@ -49,13 +49,17 @@ namespace blt::gp struct argc_t { - blt::size_t argc = 0; - blt::size_t argc_context = 0; + blt::u32 argc = 0; + blt::u32 argc_context = 0; }; struct operator_info { - + std::vector argument_types; + type_id return_type; + argc_t argc; + detail::callable_t function; + detail::transfer_t transfer; }; struct operator_storage @@ -65,9 +69,9 @@ namespace blt::gp blt::expanding_buffer> non_terminals; blt::expanding_buffer>> operators_ordered_terminals; // indexed from OPERATOR ID (operator number) + blt::hashset_t static_types; blt::expanding_buffer> argument_types; blt::expanding_buffer operator_argc; - blt::hashset_t static_types; std::vector operators; std::vector transfer_funcs; }; diff --git a/include/blt/gp/typesystem.h b/include/blt/gp/typesystem.h index 195a642..b549fa0 100644 --- a/include/blt/gp/typesystem.h +++ b/include/blt/gp/typesystem.h @@ -88,8 +88,10 @@ namespace blt::gp template inline type register_type() { - types.insert({blt::type_string_raw(), type::make_type(types.size())}); - return types[blt::type_string_raw()]; + auto t = type::make_type(types.size()); + types.insert({blt::type_string_raw(), t}); + types_from_id[t.id()] = t; + return t; } template @@ -100,13 +102,7 @@ namespace blt::gp inline type get_type(type_id id) { - for (const auto& v : types) - { - if (v.second.id() == id) - return v.second; - } - BLT_ABORT(("Type " + std::to_string(id) + " does not exist").c_str()); - std::exit(0); + return types_from_id[id]; } /** @@ -126,6 +122,7 @@ namespace blt::gp private: blt::hashmap_t types; + blt::expanding_buffer types_from_id; }; } diff --git a/lib/blt b/lib/blt index f3451b5..57ddcfc 160000 --- a/lib/blt +++ b/lib/blt @@ -1 +1 @@ -Subproject commit f3451b57ab249fdcf5ccedd64cbd56b2a64e2de2 +Subproject commit 57ddcfca1e72245b8e7e59a2f6ccf2efda1b29b3