Rename 'interpreter.hpp' -> 'exec.hpp'

This commit is contained in:
Nikita Lisitsa 2025-12-17 15:53:24 +03:00
parent d4a4d4dbef
commit ff4d0a9c3e
4 changed files with 25 additions and 25 deletions

View file

@ -1,6 +1,6 @@
#include <pslang/parser/parser.hpp>
#include <pslang/parser/error.hpp>
#include <pslang/interpreter/interpreter.hpp>
#include <pslang/interpreter/exec.hpp>
#include <pslang/ast/statement.hpp>
#include <pslang/ast/print.hpp>
@ -54,7 +54,7 @@ int main(int argc, char ** argv) try
std::cout << std::flush;
}
interpreter::execute(context, ast);
interpreter::exec(context, ast);
if (dump)
interpreter::dump(std::cout, context);

View file

@ -6,6 +6,6 @@
namespace pslang::interpreter
{
void execute(context & context, ast::statement_list_ptr const & statements);
void exec(context & context, ast::statement_list_ptr const & statements);
}

View file

@ -1,5 +1,5 @@
#include <pslang/interpreter/eval.hpp>
#include <pslang/interpreter/interpreter.hpp>
#include <pslang/interpreter/exec.hpp>
#include <pslang/interpreter/value.hpp>
#include <pslang/ast/expression.hpp>
#include <pslang/type/print.hpp>
@ -413,7 +413,7 @@ namespace pslang::interpreter
auto expected_return_type = jt->second.return_type;
execute(context, jt->second.statements);
exec(context, jt->second.statements);
auto actual_return_type = type_of(context.scope_stack.back().return_value);
if (!type::equal(actual_return_type, *expected_return_type))

View file

@ -1,4 +1,4 @@
#include <pslang/interpreter/interpreter.hpp>
#include <pslang/interpreter/exec.hpp>
#include <pslang/interpreter/eval.hpp>
#include <pslang/ast/statement.hpp>
#include <pslang/type/print.hpp>
@ -30,12 +30,12 @@ namespace pslang::interpreter
context & context_;
};
void execute_impl(context & context, ast::expression_ptr const & expression)
void exec_impl(context & context, ast::expression_ptr const & expression)
{
eval(context, expression);
}
void execute_impl(context & context, ast::assignment const & assignment)
void exec_impl(context & context, ast::assignment const & assignment)
{
std::string name;
if (auto identifier = std::get_if<ast::identifier>(assignment.lhs.get()))
@ -70,7 +70,7 @@ namespace pslang::interpreter
throw std::runtime_error("Identifier \"" + name + "\" is not defined");
}
void execute_impl(context & context, ast::variable_declaration const & variable_declaration)
void exec_impl(context & context, ast::variable_declaration const & variable_declaration)
{
auto & scope = context.scope_stack.back();
if (scope.variables.count(variable_declaration.name) > 0)
@ -93,26 +93,26 @@ namespace pslang::interpreter
context.scope_stack.back().variables[variable_declaration.name] = {.category = variable_declaration.category, .value = value};
}
void execute_impl(context & context, ast::if_block const &)
void exec_impl(context & context, ast::if_block const &)
{
throw std::runtime_error("Internal interpreter error: if blocks cannot be present in the final AST");
}
void execute_impl(context & context, ast::else_block const &)
void exec_impl(context & context, ast::else_block const &)
{
throw std::runtime_error("Internal interpreter error: else blocks cannot be present in the final AST");
}
void execute_impl(context & context, ast::else_if_block const &)
void exec_impl(context & context, ast::else_if_block const &)
{
throw std::runtime_error("Internal interpreter error: else if blocks cannot be present in the final AST");
}
void execute_impl(context & context, ast::if_chain const & if_chain)
void exec_impl(context & context, ast::if_chain const & if_chain)
{
for (auto const & block : if_chain.blocks)
{
bool do_execute = true;
bool do_exec = true;
if (block.condition)
{
@ -127,20 +127,20 @@ namespace pslang::interpreter
throw std::runtime_error(os.str());
}
do_execute = std::get<bool_value>(std::get<primitive_value>(value)).value;
do_exec = std::get<bool_value>(std::get<primitive_value>(value)).value;
}
if (!do_execute)
if (!do_exec)
continue;
context.scope_stack.emplace_back();
stack_pop_guard guard(context);
execute(context, block.statements);
exec(context, block.statements);
break;
}
}
void execute_impl(context & context, ast::while_block const & while_block)
void exec_impl(context & context, ast::while_block const & while_block)
{
while (true)
{
@ -159,14 +159,14 @@ namespace pslang::interpreter
{
context.scope_stack.emplace_back();
stack_pop_guard guard(context);
execute(context, while_block.statements);
exec(context, while_block.statements);
}
else
break;
}
}
void execute_impl(context & context, ast::function_definition const & function_definition)
void exec_impl(context & context, ast::function_definition const & function_definition)
{
auto & scope = context.scope_stack.back();
if (scope.functions.count(function_definition.name) > 0)
@ -178,7 +178,7 @@ namespace pslang::interpreter
function.statements = function_definition.statements;
}
void execute_impl(context & context, ast::return_statement const & return_statement)
void exec_impl(context & context, ast::return_statement const & return_statement)
{
auto value = return_statement.value ? eval(context, return_statement.value) : unit_value{};
for (auto it = context.scope_stack.rbegin(); it != context.scope_stack.rend(); ++it)
@ -193,13 +193,13 @@ namespace pslang::interpreter
throw std::runtime_error("Cannot return outside of a function");
}
void execute_impl(context & context, ast::statement_list_ptr const & statements)
void exec_impl(context & context, ast::statement_list_ptr const & statements)
{
for (auto const & statement : statements->statements)
{
try
{
std::visit([&](auto const & statement){ execute_impl(context, statement); }, *statement);
std::visit([&](auto const & statement){ exec_impl(context, statement); }, *statement);
}
catch (return_exception const &)
{
@ -213,9 +213,9 @@ namespace pslang::interpreter
}
void execute(context & context, ast::statement_list_ptr const & statements)
void exec(context & context, ast::statement_list_ptr const & statements)
{
execute_impl(context, statements);
exec_impl(context, statements);
}
}