From 76c34baaec79f6772b4bdbe4593958685bb2eb6e Mon Sep 17 00:00:00 2001 From: Brett Date: Wed, 13 Mar 2024 12:16:25 -0400 Subject: [PATCH] more types --- CMakeLists.txt | 2 +- include/lilfbtf/fwddecl.h | 5 ++++- include/lilfbtf/tree.h | 30 ++++++++++++++++-------------- include/lilfbtf/type.h | 23 ++++++++++++++--------- src/tree.cpp | 6 ++++-- src/type.cpp | 20 ++++++++++++++------ tests/src/tests4.cpp | 3 ++- 7 files changed, 55 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 80620ab..9040884 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.25) -project(lilfbtf5 VERSION 0.1.18) +project(lilfbtf5 VERSION 0.1.19) option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF) option(ENABLE_UBSAN "Enable the ub sanitizer" OFF) diff --git a/include/lilfbtf/fwddecl.h b/include/lilfbtf/fwddecl.h index 3efc6c4..50de4b9 100644 --- a/include/lilfbtf/fwddecl.h +++ b/include/lilfbtf/fwddecl.h @@ -37,7 +37,10 @@ namespace fb class type_engine_t; class gp_system_t; - using type_id = blt::size_t; + // no way we are going to have more than 4billion types or functions. + using type_id = blt::u32; + using function_id = blt::u32; + using arg_c_t = blt::size_t; using func_t_call_t = std::function)>; using function_name = const std::string&; using type_name = const std::string&; diff --git a/include/lilfbtf/tree.h b/include/lilfbtf/tree.h index 79fe5ef..ae4bf30 100644 --- a/include/lilfbtf/tree.h +++ b/include/lilfbtf/tree.h @@ -31,23 +31,20 @@ namespace fb class func_t { private: - blt::size_t argc_ = 0; + arg_c_t argc_ = 0; type_id type; + function_id function; const func_t_call_t& func; protected: blt::unsafe::any_t value; public: - explicit func_t(blt::size_t argc, const func_t_call_t& func, type_id type): - argc_(argc), type(type), func(func) - {} + explicit func_t(arg_c_t argc, const func_t_call_t& func, type_id output_type, function_id function_type); - [[nodiscard]] inline blt::size_t argc() const + [[nodiscard]] inline arg_c_t argc() const { return argc_; } [[nodiscard]] inline blt::unsafe::any_t getValue() const - { - return value; - } + { return value; } inline func_t& setValue(blt::unsafe::any_t val) { @@ -55,15 +52,20 @@ namespace fb return *this; } + /** + * @return the type_id that this function container will output + */ [[nodiscard]] inline type_id getType() const - { - return type; - } + { return type; } + + /** + * @return the function id of this function container + */ + [[nodiscard]] inline type_id getFunction() const + { return function; } inline void call(blt::span args) - { - func(*this, args); - }; + { func(*this, args); }; ~func_t() = default; }; diff --git a/include/lilfbtf/type.h b/include/lilfbtf/type.h index e8d5d9c..518e262 100644 --- a/include/lilfbtf/type.h +++ b/include/lilfbtf/type.h @@ -29,12 +29,16 @@ namespace fb { private: // type name -> type id - blt::hashmap_t name_to_id; + blt::hashmap_t name_to_type; // also used to assign IDs - std::vector id_to_name; + std::vector type_to_name; + + blt::hashmap_t name_to_function; + std::vector function_to_name; + // TODO: we don't need a hashmap for this. // Also a bad idea to store references, however these functions should be declared statically so this isn't as big of an issue. - blt::hashmap_t> functions; + blt::hashmap_t> functions; // function names -> type_id blt::hashmap_t function_outputs; // function names -> list of type_id for parameters where index 0 = arg 1 @@ -44,16 +48,17 @@ namespace fb type_id register_type(type_name type_name); - inline type_id get_type_id(type_name name) - { - return name_to_id[name]; - } + function_id register_function(function_name func_name, func_t_call_t& func); - type_engine_t& register_function(function_name func_name, func_t_call_t& func); + inline type_id get_type_id(type_name name) + { return name_to_type[name]; } + + inline type_id get_function_id(function_name name) + { return name_to_function[name]; } type_engine_t& associate_output(function_name func_name, type_name type_name); - type_engine_t& associate_input(function_name func_name, type_name) + type_engine_t& associate_input(function_name func_name, type_name); }; } diff --git a/src/tree.cpp b/src/tree.cpp index ca6b3c4..c63d358 100644 --- a/src/tree.cpp +++ b/src/tree.cpp @@ -18,7 +18,9 @@ namespace fb { - - + + func_t::func_t(blt::size_t argc, const func_t_call_t& func, type_id output_type, function_id function_type): + argc_(argc), type(output_type), function(function_type), func(func) + {} } \ No newline at end of file diff --git a/src/type.cpp b/src/type.cpp index 6693004..8bba3f1 100644 --- a/src/type.cpp +++ b/src/type.cpp @@ -22,16 +22,18 @@ namespace fb type_id type_engine_t::register_type(type_name type_name) { - type_id id = id_to_name.size(); - id_to_name.push_back(type_name); - name_to_id[type_name] = id; + type_id id = type_to_name.size(); + type_to_name.push_back(type_name); + name_to_type[type_name] = id; return id; } - type_engine_t& type_engine_t::register_function(function_name func_name, func_t_call_t& func) + function_id type_engine_t::register_function(function_name func_name, func_t_call_t& func) { - functions.insert({func_name, func}); - return *this; + function_id id = function_to_name.size(); + name_to_function[func_name] = id; + functions.insert({id, func}); + return id; } type_engine_t& type_engine_t::associate_output(function_name func_name, type_name type_name) @@ -39,4 +41,10 @@ namespace fb function_outputs[func_name] = get_type_id(type_name); return *this; } + + type_engine_t& type_engine_t::associate_input(function_name func_name, type_name) + { + + return *this; + } } \ No newline at end of file diff --git a/tests/src/tests4.cpp b/tests/src/tests4.cpp index fdf6d90..91cd786 100644 --- a/tests/src/tests4.cpp +++ b/tests/src/tests4.cpp @@ -32,6 +32,8 @@ #include "blt/std/allocator.h" #include "blt/std/format.h" #include "blt/std/system.h" +#include "lilfbtf/tree.h" + namespace fb { @@ -1491,5 +1493,4 @@ namespace fb BLT_INFO("Current bytes: %s, blocks: %ld", blt::string::fromBytes(alloc_2.getStats().getAllocatedBytes()).c_str(), alloc_2.getStats().getAllocatedBlocks()); } - } \ No newline at end of file