Femboy_GP/src/type.cpp

67 lines
2.5 KiB
C++
Raw Normal View History

2024-03-12 16:53:27 -04:00
/*
* <Short Description>
* Copyright (C) 2024 Brett Terpstra
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <lilfbtf/type.h>
namespace fb
{
2024-03-12 17:16:32 -04:00
type_id type_engine_t::register_type(type_name type_name)
{
2024-03-13 12:16:25 -04:00
type_id id = type_to_name.size();
type_to_name.push_back(type_name);
name_to_type[type_name] = id;
2024-03-12 17:16:32 -04:00
return id;
}
2024-03-14 08:47:14 -04:00
function_id type_engine_t::register_function(function_name func_name, type_name output, func_t_call_t& func,
2024-03-14 08:36:06 -04:00
std::optional<std::reference_wrapper<func_t_init_t>> initializer)
2024-03-12 17:16:32 -04:00
{
2024-03-13 12:16:25 -04:00
function_id id = function_to_name.size();
2024-03-14 08:47:14 -04:00
type_id tid = get_type_id(output);
2024-03-13 12:16:25 -04:00
name_to_function[func_name] = id;
2024-03-13 19:04:22 -04:00
functions.insert(id, func);
2024-03-14 08:47:14 -04:00
non_terminals[tid].push_back(id);
all_non_terminals.emplace_back(tid, id);
2024-03-14 08:36:06 -04:00
if (auto& init = initializer)
function_initializer.insert(id, init.value());
2024-03-13 12:16:25 -04:00
return id;
2024-03-12 17:16:32 -04:00
}
2024-03-13 19:04:22 -04:00
type_engine_t& type_engine_t::associate_input(function_name func_name, const std::vector<std::string>& types)
2024-03-12 17:16:32 -04:00
{
2024-03-13 19:04:22 -04:00
auto id = get_function_id(func_name);
std::vector<type_id> type_ids;
for (const auto& v : types)
type_ids.push_back(get_type_id(v));
function_inputs[id] = std::move(type_ids);
2024-03-12 17:16:32 -04:00
return *this;
}
2024-03-13 12:16:25 -04:00
2024-03-14 08:47:14 -04:00
function_id type_engine_t::register_terminal_function(function_name func_name, type_name output, func_t_call_t& func,
2024-03-14 08:36:06 -04:00
std::optional<std::reference_wrapper<func_t_init_t>> initializer)
2024-03-13 12:16:25 -04:00
{
2024-03-13 19:04:22 -04:00
function_id id = function_to_name.size();
2024-03-14 08:47:14 -04:00
type_id tid = get_type_id(output);
2024-03-13 19:04:22 -04:00
name_to_function[func_name] = id;
functions.insert(id, func);
2024-03-14 08:47:14 -04:00
terminals[tid].push_back(id);
2024-03-14 08:36:06 -04:00
if (auto& init = initializer)
function_initializer.insert(id, init.value());
2024-03-13 19:04:22 -04:00
return id;
2024-03-13 12:16:25 -04:00
}
2024-03-12 16:53:27 -04:00
}