tree type
parent
36bb3ffefa
commit
48c77af126
|
@ -1,5 +1,5 @@
|
|||
cmake_minimum_required(VERSION 3.25)
|
||||
project(lilfbtf5 VERSION 0.1.20)
|
||||
project(lilfbtf5 VERSION 0.1.21)
|
||||
|
||||
option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF)
|
||||
option(ENABLE_UBSAN "Enable the ub sanitizer" OFF)
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <functional>
|
||||
#include "blt/std/ranges.h"
|
||||
#include "blt/std/allocator.h"
|
||||
#include "type.h"
|
||||
#include <lilfbtf/fwddecl.h>
|
||||
|
||||
namespace fb
|
||||
|
@ -104,12 +105,14 @@ namespace fb
|
|||
};
|
||||
}
|
||||
|
||||
|
||||
class tree_t
|
||||
{
|
||||
private:
|
||||
blt::bump_allocator<blt::BLT_2MB_SIZE, false>& alloc;
|
||||
type_engine_t& types;
|
||||
public:
|
||||
tree_t(blt::bump_allocator<blt::BLT_2MB_SIZE, false>& alloc, type_engine_t& types);
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <blt/std/memory_util.h>
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
#include <optional>
|
||||
|
||||
namespace fb
|
||||
{
|
||||
|
@ -110,7 +111,7 @@ namespace fb
|
|||
// function id -> list of type_id for parameters where index 0 = arg 1
|
||||
associative_array<function_id, std::vector<type_id>> function_inputs;
|
||||
|
||||
associative_array<function_id, std::reference_wrapper<func_t_init_t>> terminal_initializer;
|
||||
associative_array<function_id, std::reference_wrapper<func_t_init_t>> function_initializer;
|
||||
associative_array<type_id, std::vector<function_id>, true> terminals;
|
||||
associative_array<type_id, std::vector<function_id>, true> non_terminals;
|
||||
public:
|
||||
|
@ -118,9 +119,11 @@ namespace fb
|
|||
|
||||
type_id register_type(type_name type_name);
|
||||
|
||||
function_id register_function(function_name func_name, type_id output, func_t_call_t& func);
|
||||
function_id register_function(function_name func_name, type_id output, func_t_call_t& func,
|
||||
std::optional<std::reference_wrapper<func_t_init_t>> initializer);
|
||||
|
||||
function_id register_terminal_function(function_name func_name, type_id output, func_t_call_t& func, func_t_init_t& initializer);
|
||||
function_id register_terminal_function(function_name func_name, type_id output, func_t_call_t& func,
|
||||
std::optional<std::reference_wrapper<func_t_init_t>> initializer);
|
||||
|
||||
inline type_id get_type_id(type_name name)
|
||||
{ return name_to_type[name]; }
|
||||
|
@ -137,7 +140,7 @@ namespace fb
|
|||
{ return get_function(get_function_id(name)); }
|
||||
|
||||
inline func_t_init_t& get_function_initializer(function_id id)
|
||||
{ return terminal_initializer[id]; }
|
||||
{ return function_initializer[id]; }
|
||||
|
||||
inline func_t_init_t& get_function_initializer(function_name name)
|
||||
{ return get_function_initializer(get_function_id(name)); }
|
||||
|
|
|
@ -23,4 +23,8 @@ namespace fb
|
|||
argc_(argc), type(output_type), function(function_type), func(func)
|
||||
{}
|
||||
|
||||
tree_t::tree_t(blt::bump_allocator<blt::BLT_2MB_SIZE, false>& alloc, type_engine_t& types): alloc(alloc), types(types)
|
||||
{}
|
||||
|
||||
|
||||
}
|
11
src/type.cpp
11
src/type.cpp
|
@ -28,12 +28,15 @@ namespace fb
|
|||
return id;
|
||||
}
|
||||
|
||||
function_id type_engine_t::register_function(function_name func_name, type_id output, func_t_call_t& func)
|
||||
function_id type_engine_t::register_function(function_name func_name, type_id output, func_t_call_t& func,
|
||||
std::optional<std::reference_wrapper<func_t_init_t>> initializer)
|
||||
{
|
||||
function_id id = function_to_name.size();
|
||||
name_to_function[func_name] = id;
|
||||
functions.insert(id, func);
|
||||
non_terminals[output].push_back(id);
|
||||
if (auto& init = initializer)
|
||||
function_initializer.insert(id, init.value());
|
||||
return id;
|
||||
}
|
||||
|
||||
|
@ -47,13 +50,15 @@ namespace fb
|
|||
return *this;
|
||||
}
|
||||
|
||||
function_id type_engine_t::register_terminal_function(function_name func_name, type_id output, func_t_call_t& func, func_t_init_t& initializer)
|
||||
function_id type_engine_t::register_terminal_function(function_name func_name, type_id output, func_t_call_t& func,
|
||||
std::optional<std::reference_wrapper<func_t_init_t>> initializer)
|
||||
{
|
||||
function_id id = function_to_name.size();
|
||||
name_to_function[func_name] = id;
|
||||
functions.insert(id, func);
|
||||
terminals[output].push_back(id);
|
||||
terminal_initializer.insert(id, initializer);
|
||||
if (auto& init = initializer)
|
||||
function_initializer.insert(id, init.value());
|
||||
return id;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue