more types
parent
2d770e59c9
commit
76c34baaec
|
@ -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)
|
||||
|
|
|
@ -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<void(func_t&, blt::span<detail::node_t*>)>;
|
||||
using function_name = const std::string&;
|
||||
using type_name = const std::string&;
|
||||
|
|
|
@ -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<detail::node_t*> args)
|
||||
{
|
||||
func(*this, args);
|
||||
};
|
||||
{ func(*this, args); };
|
||||
|
||||
~func_t() = default;
|
||||
};
|
||||
|
|
|
@ -29,12 +29,16 @@ namespace fb
|
|||
{
|
||||
private:
|
||||
// type name -> type id
|
||||
blt::hashmap_t<std::string, type_id> name_to_id;
|
||||
blt::hashmap_t<std::string, type_id> name_to_type;
|
||||
// also used to assign IDs
|
||||
std::vector<std::string> id_to_name;
|
||||
std::vector<std::string> type_to_name;
|
||||
|
||||
blt::hashmap_t<std::string, function_id> name_to_function;
|
||||
std::vector<std::string> 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<std::string, std::reference_wrapper<func_t_call_t>> functions;
|
||||
blt::hashmap_t<function_id, 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
|
||||
|
@ -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);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
{}
|
||||
|
||||
}
|
20
src/type.cpp
20
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;
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue