type system

main
Brett 2024-03-12 17:16:32 -04:00
parent 6ca18b97aa
commit 2d770e59c9
4 changed files with 38 additions and 11 deletions

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.25) 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_ADDRSAN "Enable the address sanitizer" OFF)
option(ENABLE_UBSAN "Enable the ub sanitizer" OFF) option(ENABLE_UBSAN "Enable the ub sanitizer" OFF)

View File

@ -22,6 +22,7 @@
#include <blt/std/types.h> #include <blt/std/types.h>
#include <functional> #include <functional>
#include "blt/std/ranges.h" #include "blt/std/ranges.h"
#include <string>
namespace fb namespace fb
{ {
@ -38,6 +39,8 @@ namespace fb
using type_id = blt::size_t; using type_id = blt::size_t;
using func_t_call_t = std::function<void(func_t&, blt::span<detail::node_t*>)>; using func_t_call_t = std::function<void(func_t&, blt::span<detail::node_t*>)>;
using function_name = const std::string&;
using type_name = const std::string&;
} }
#endif //LILFBTF5_FWDDECL_H #endif //LILFBTF5_FWDDECL_H

View File

@ -28,27 +28,32 @@ namespace fb
class type_engine_t class type_engine_t
{ {
private: private:
// type name -> type id
blt::hashmap_t<std::string, type_id> name_to_id; blt::hashmap_t<std::string, type_id> name_to_id;
// also used to assign IDs // also used to assign IDs
std::vector<std::string> id_to_name; std::vector<std::string> id_to_name;
// TODO: we don't need a hashmap for this. // 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. // 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<type_id, std::reference_wrapper<func_t_call_t>> functions; blt::hashmap_t<std::string, std::reference_wrapper<func_t_call_t>> functions;
// function names -> type_id
blt::hashmap_t<std::string, type_id> function_outputs;
// function names -> list of type_id for parameters where index 0 = arg 1
blt::hashmap_t<std::string, std::vector<type_id>> function_inputs;
public: public:
type_engine_t() = default; 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(); return name_to_id[name];
id_to_name.push_back(type_name);
name_to_id[type_name] = id;
return id;
} }
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)
}; };
} }

View File

@ -19,5 +19,24 @@
namespace fb 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;
}
} }