type system
parent
6ca18b97aa
commit
2d770e59c9
|
@ -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)
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <blt/std/types.h>
|
||||
#include <functional>
|
||||
#include "blt/std/ranges.h"
|
||||
#include <string>
|
||||
|
||||
namespace fb
|
||||
{
|
||||
|
@ -38,6 +39,8 @@ namespace fb
|
|||
|
||||
using type_id = blt::size_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
|
||||
|
|
|
@ -28,27 +28,32 @@ namespace fb
|
|||
class type_engine_t
|
||||
{
|
||||
private:
|
||||
// type name -> type id
|
||||
blt::hashmap_t<std::string, type_id> name_to_id;
|
||||
// also used to assign IDs
|
||||
std::vector<std::string> 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<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:
|
||||
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)
|
||||
};
|
||||
}
|
||||
|
||||
|
|
19
src/type.cpp
19
src/type.cpp
|
@ -20,4 +20,23 @@
|
|||
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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue