Femboy_GP/src/type.cpp

59 lines
2.0 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-13 19:04:22 -04:00
function_id type_engine_t::register_function(function_name func_name, type_id output, func_t_call_t& func)
2024-03-12 17:16:32 -04:00
{
2024-03-13 12:16:25 -04:00
function_id id = function_to_name.size();
name_to_function[func_name] = id;
2024-03-13 19:04:22 -04:00
functions.insert(id, func);
non_terminals[output].push_back(id);
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-13 19:04:22 -04:00
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)
2024-03-13 12:16:25 -04:00
{
2024-03-13 19:04:22 -04:00
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);
return id;
2024-03-13 12:16:25 -04:00
}
2024-03-12 16:53:27 -04:00
}