main
Brett 2024-03-14 10:34:57 -04:00
parent 39f8fe44c7
commit ee917ea787
4 changed files with 30 additions and 7 deletions

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.25) cmake_minimum_required(VERSION 3.25)
project(lilfbtf5 VERSION 0.1.23) project(lilfbtf5 VERSION 0.1.24)
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

@ -42,7 +42,7 @@ namespace fb
if constexpr (init) if constexpr (init)
{ {
for (blt::size_t i = size_; i < new_size; i++) for (blt::size_t i = size_; i < new_size; i++)
new(&new_size[i]) T(); new(&new_data[i]) T();
} }
for (blt::size_t i = 0; i < size_; i++) for (blt::size_t i = 0; i < size_; i++)
new(&new_data[i]) T(std::move(data_[i])); new(&new_data[i]) T(std::move(data_[i]));
@ -55,6 +55,20 @@ namespace fb
associative_array(): size_(0), data_(nullptr) associative_array(): size_(0), data_(nullptr)
{} {}
[[nodiscard]] const T& at(K index) const
{
while (index >= size_)
expand();
return data_[index];
}
T& at(K index)
{
while (index >= size_)
expand();
return data_[index];
}
T& operator[](K index) T& operator[](K index)
{ {
return data_[index]; return data_[index];
@ -109,7 +123,7 @@ namespace fb
// 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.
associative_array<function_id, std::reference_wrapper<const func_t_call_t>> functions; associative_array<function_id, std::reference_wrapper<const func_t_call_t>> functions;
// function id -> list of type_id for parameters where index 0 = arg 1 // 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::vector<type_id>, true> function_inputs;
associative_array<function_id, arg_c_t> function_argc; associative_array<function_id, arg_c_t> function_argc;
associative_array<function_id, std::reference_wrapper<const func_t_init_t>> function_initializer; associative_array<function_id, std::reference_wrapper<const func_t_init_t>> function_initializer;

View File

@ -35,7 +35,7 @@ namespace fb
type_id tid = get_type_id(output); type_id tid = get_type_id(output);
name_to_function[func_name] = id; name_to_function[func_name] = id;
functions.insert(id, func); functions.insert(id, func);
non_terminals[tid].push_back(id); non_terminals.at(tid).push_back(id);
all_non_terminals.emplace_back(tid, id); all_non_terminals.emplace_back(tid, id);
function_argc.insert(id, argc); function_argc.insert(id, argc);
if (auto& init = initializer) if (auto& init = initializer)
@ -49,7 +49,7 @@ namespace fb
std::vector<type_id> type_ids; std::vector<type_id> type_ids;
for (const auto& v : types) for (const auto& v : types)
type_ids.push_back(get_type_id(v)); type_ids.push_back(get_type_id(v));
function_inputs[id] = std::move(type_ids); function_inputs.at(id) = std::move(type_ids);
return *this; return *this;
} }
@ -60,7 +60,7 @@ namespace fb
type_id tid = get_type_id(output); type_id tid = get_type_id(output);
name_to_function[func_name] = id; name_to_function[func_name] = id;
functions.insert(id, func); functions.insert(id, func);
terminals[tid].push_back(id); terminals.at(tid).push_back(id);
function_argc.insert(id, 0); function_argc.insert(id, 0);
if (auto& init = initializer) if (auto& init = initializer)
function_initializer.insert(id, init.value()); function_initializer.insert(id, init.value());

View File

@ -35,7 +35,13 @@ const fb::func_t_call_t div_f = [](fb::func_t& us, blt::span<fb::detail::node_t*
us.setValue(args[0]->value().any_cast<blt::u8>() + dim); us.setValue(args[0]->value().any_cast<blt::u8>() + dim);
}; };
const fb::func_t_call_t value_f = [](fb::func_t&, blt::span<fb::detail::node_t*>) {}; const fb::func_t_call_t empty_f = [](fb::func_t&, blt::span<fb::detail::node_t*>) {};
const fb::func_t_init_t value_init_f = [](fb::func_t& us){
us.setValue(fb::random_value());
};
const fb::func_t_init_t bool_init_f = [](fb::func_t& us){
us.setValue(fb::choice());
};
const fb::func_t_call_t if_f = [](fb::func_t& us, blt::span<fb::detail::node_t*> args) { const fb::func_t_call_t if_f = [](fb::func_t& us, blt::span<fb::detail::node_t*> args) {
if (args[0]->value().any_cast<bool>()) if (args[0]->value().any_cast<bool>())
us.setValue(args[1]->value().any_cast<blt::u8>()); us.setValue(args[1]->value().any_cast<blt::u8>());
@ -131,6 +137,9 @@ int main(int argc, const char** argv)
typeEngine.register_function("or_b", "bool", or_b_f, 2); typeEngine.register_function("or_b", "bool", or_b_f, 2);
typeEngine.register_function("or_n", "u8", or_n_f, 2); typeEngine.register_function("or_n", "u8", or_n_f, 2);
typeEngine.register_terminal_function("value", "u8", empty_f, value_init_f);
typeEngine.register_terminal_function("bool_value", "bool", empty_f, bool_init_f);
typeEngine.associate_input("add", {"u8", "u8"}); typeEngine.associate_input("add", {"u8", "u8"});
typeEngine.associate_input("sub", {"u8", "u8"}); typeEngine.associate_input("sub", {"u8", "u8"});
typeEngine.associate_input("mul", {"u8", "u8"}); typeEngine.associate_input("mul", {"u8", "u8"});