From 2d770e59c9ca3b856fedcb2ed169fef5ac767313 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Tue, 12 Mar 2024 17:16:32 -0400 Subject: [PATCH] type system --- CMakeLists.txt | 2 +- include/lilfbtf/fwddecl.h | 3 +++ include/lilfbtf/type.h | 23 ++++++++++++++--------- src/type.cpp | 21 ++++++++++++++++++++- 4 files changed, 38 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 717d422..80620ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.25) -project(lilfbtf5 VERSION 0.1.17) +project(lilfbtf5 VERSION 0.1.18) 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 ba1f696..3efc6c4 100644 --- a/include/lilfbtf/fwddecl.h +++ b/include/lilfbtf/fwddecl.h @@ -22,6 +22,7 @@ #include #include #include "blt/std/ranges.h" +#include namespace fb { @@ -38,6 +39,8 @@ namespace fb using type_id = blt::size_t; using func_t_call_t = std::function)>; + using function_name = const std::string&; + using type_name = const std::string&; } #endif //LILFBTF5_FWDDECL_H diff --git a/include/lilfbtf/type.h b/include/lilfbtf/type.h index b033b97..e8d5d9c 100644 --- a/include/lilfbtf/type.h +++ b/include/lilfbtf/type.h @@ -28,27 +28,32 @@ namespace fb class type_engine_t { private: + // type name -> type id blt::hashmap_t name_to_id; // also used to assign IDs std::vector id_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 + blt::hashmap_t> function_inputs; public: type_engine_t() = default; - type_id register_type(const std::string& type_name) + type_id register_type(type_name type_name); + + inline type_id get_type_id(type_name name) { - type_id id = id_to_name.size(); - id_to_name.push_back(type_name); - name_to_id[type_name] = id; - return id; + return name_to_id[name]; } - void register_function(const std::string& type_name, func_t_call_t& func) - { + type_engine_t& register_function(function_name func_name, func_t_call_t& func); - } + type_engine_t& associate_output(function_name func_name, type_name type_name); + + type_engine_t& associate_input(function_name func_name, type_name) }; } diff --git a/src/type.cpp b/src/type.cpp index 1c078c1..6693004 100644 --- a/src/type.cpp +++ b/src/type.cpp @@ -19,5 +19,24 @@ 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; + return id; + } + + type_engine_t& type_engine_t::register_function(function_name func_name, func_t_call_t& func) + { + functions.insert({func_name, func}); + return *this; + } + + type_engine_t& type_engine_t::associate_output(function_name func_name, type_name type_name) + { + function_outputs[func_name] = get_type_id(type_name); + return *this; + } } \ No newline at end of file