2024-03-07 09:15:11 +01:00
|
|
|
#include "elna/source/result.hpp"
|
2024-02-22 21:29:25 +01:00
|
|
|
|
2024-03-07 09:15:11 +01:00
|
|
|
namespace elna::source
|
2024-03-03 13:11:39 +01:00
|
|
|
{
|
2024-03-09 08:36:07 +01:00
|
|
|
error::error(const position position)
|
|
|
|
: m_position(position)
|
2024-02-22 21:29:25 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-03-03 13:11:39 +01:00
|
|
|
std::size_t error::line() const noexcept
|
2024-02-22 21:29:25 +01:00
|
|
|
{
|
2024-03-09 08:36:07 +01:00
|
|
|
return this->m_position.line;
|
2024-02-22 21:29:25 +01:00
|
|
|
}
|
|
|
|
|
2024-03-03 13:11:39 +01:00
|
|
|
std::size_t error::column() const noexcept
|
2024-02-22 21:29:25 +01:00
|
|
|
{
|
2024-03-09 08:36:07 +01:00
|
|
|
return this->m_position.column;
|
2024-02-22 21:29:25 +01:00
|
|
|
}
|
2024-03-14 08:52:45 +01:00
|
|
|
|
|
|
|
name_collision::name_collision(const std::string& name, const position current, const position previous)
|
|
|
|
: error(current), name(name), previous(previous)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string name_collision::what() const
|
|
|
|
{
|
|
|
|
return "Name '" + name + "' was already defined";
|
|
|
|
}
|
|
|
|
|
2024-03-19 09:35:50 +01:00
|
|
|
symbol_table::symbol_table()
|
|
|
|
{
|
|
|
|
enter("writei", std::make_shared<intrinsic_info>());
|
|
|
|
enter("writeb", std::make_shared<intrinsic_info>());
|
|
|
|
}
|
|
|
|
|
2024-03-14 08:52:45 +01:00
|
|
|
std::shared_ptr<info> symbol_table::lookup(const std::string& name)
|
|
|
|
{
|
|
|
|
auto entry = entries.find(name);
|
|
|
|
if (entry == entries.cend())
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return entry->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void symbol_table::enter(const std::string& name, std::shared_ptr<info> entry)
|
|
|
|
{
|
|
|
|
entries.insert_or_assign(name, entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
info::~info()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
info::info()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
constant_info::constant_info(const std::int32_t value)
|
|
|
|
: m_value(value)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
constant_info::~constant_info()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::int32_t constant_info::value() const noexcept
|
|
|
|
{
|
|
|
|
return m_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
variable_info::~variable_info()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
procedure_info::~procedure_info()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::size_t procedure_info::stack_size() const noexcept
|
|
|
|
{
|
|
|
|
return this->local_stack_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void procedure_info::stack_size(const std::size_t size) noexcept
|
|
|
|
{
|
|
|
|
this->local_stack_size = size;
|
|
|
|
}
|
2024-03-19 09:35:50 +01:00
|
|
|
|
|
|
|
intrinsic_info::~intrinsic_info()
|
|
|
|
{
|
|
|
|
}
|
2024-03-03 13:11:39 +01:00
|
|
|
}
|