#include "elna/source/types.hpp" #include "elna/source/symbol_table.hpp" namespace elna::source { symbol_table::symbol_table(std::shared_ptr scope) : outer_scope(scope) { if (scope == nullptr) { auto boolean_info = std::make_shared(boolean_type); auto int_info = std::make_shared(int_type); enter("Boolean", boolean_info); enter("Int", int_info); auto writei = std::make_shared(); writei->parameter_infos.emplace_back(int_info->type()); enter("writei", writei); auto writeb = std::make_shared(); writeb->parameter_infos.emplace_back(boolean_info->type()); enter("writeb", writeb); } } std::shared_ptr symbol_table::lookup(const std::string& name) { auto entry = entries.find(name); if (entry != entries.cend()) { return entry->second; } if (this->outer_scope != nullptr) { return this->outer_scope->lookup(name); } return nullptr; } void symbol_table::enter(const std::string& name, std::shared_ptr entry) { entries.insert_or_assign(name, entry); } std::shared_ptr symbol_table::scope() { return this->outer_scope; } info::~info() { } info::info() { } type_info::type_info(const class type& type) : info(), m_type(std::make_shared(type)) { } type_info::~type_info() { } std::shared_ptr type_info::type() const noexcept { return m_type; } 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(std::shared_ptr type) : m_type(type) { } variable_info::~variable_info() { } std::shared_ptr variable_info::type() noexcept { return m_type; } parameter_info::parameter_info(std::shared_ptr type) : m_type(type) { } parameter_info::~parameter_info() { } std::shared_ptr parameter_info::type() const noexcept { return m_type; } intrinsic_info::~intrinsic_info() { } std::size_t intrinsic_info::parameter_stack_size() const noexcept { return this->parameter_infos.size() * sizeof(std::int32_t); } procedure_info::procedure_info(std::shared_ptr outer_scope) : local_table(std::make_shared(outer_scope)) { } procedure_info::~procedure_info() { } std::shared_ptr procedure_info::scope() { return local_table; } std::size_t procedure_info::stack_size() const noexcept { return local_stack_size + argument_stack_size; } }