replace executor, task namespace: utils -> core

This commit is contained in:
ProgramSnail 2024-09-12 19:07:22 +03:00
parent 4bf3406892
commit 331d97ab48
9 changed files with 37 additions and 45 deletions

View file

@ -20,7 +20,7 @@ struct State {
// //
using Executor = utils::Executor<Exprs, Types, Names, State, Positions>; using Executor = core::Executor<Exprs, Types, Names, State, Positions>;
using ParserNode = parser::ParseTree::Node; using ParserNode = parser::ParseTree::Node;
@ -31,9 +31,9 @@ struct Args {
}; };
template <typename N> template <typename N>
using Task = utils::Task<Executor, N, Args, parser::ParseTree::Node>; using Task = core::Task<Executor, N, Args, parser::ParseTree::Node>;
template <typename N, typename Tag = utils::None> struct BuilderTask { template <typename N, typename Tag = core::None> struct BuilderTask {
static_assert(false); static_assert(false);
}; };
@ -62,7 +62,7 @@ template <typename N> struct BuilderTaskUtils : public Task<N> {
} }
// TODO: rename // TODO: rename
template <typename OtherN, typename OtherTag = utils::None, template <typename OtherN, typename OtherTag = core::None,
typename Ret = OtherN> typename Ret = OtherN>
Ret RunOther(const parser::ParseTree::Node &node, const Args &args = {}) { Ret RunOther(const parser::ParseTree::Node &node, const Args &args = {}) {
BuilderTask<OtherN, OtherTag> task(this->executor); BuilderTask<OtherN, OtherTag> task(this->executor);
@ -75,7 +75,7 @@ template <typename N> struct BuilderTaskUtils : public Task<N> {
template <typename N> struct BasicBuilderTaskBase : public BuilderTaskUtils<N> { template <typename N> struct BasicBuilderTaskBase : public BuilderTaskUtils<N> {
using BuilderTaskUtils<N>::BuilderTaskUtils; using BuilderTaskUtils<N>::BuilderTaskUtils;
template <typename OtherN, typename OtherTag = utils::None, template <typename OtherN, typename OtherTag = core::None,
typename Ret = OtherN> typename Ret = OtherN>
Ret Run(const parser::ParseTree::Node &node, const Args &args = {}) { Ret Run(const parser::ParseTree::Node &node, const Args &args = {}) {
BuilderTask<OtherN, OtherTag> task(this->executor); BuilderTask<OtherN, OtherTag> task(this->executor);
@ -87,7 +87,7 @@ template <typename N>
struct ExprBuilderTaskBase : public BuilderTaskUtils<Node> { struct ExprBuilderTaskBase : public BuilderTaskUtils<Node> {
using BuilderTaskUtils<Node>::BuilderTaskUtils; using BuilderTaskUtils<Node>::BuilderTaskUtils;
template <typename OtherN, typename OtherTag = utils::None, template <typename OtherN, typename OtherTag = core::None,
typename Ret = Node> typename Ret = Node>
Ret Run(const parser::ParseTree::Node &node, const Args &args = {}) { Ret Run(const parser::ParseTree::Node &node, const Args &args = {}) {
BuilderTask<OtherN, OtherTag> task(this->executor); BuilderTask<OtherN, OtherTag> task(this->executor);
@ -99,7 +99,7 @@ template <typename N>
struct TypeBuilderTaskBase : public BuilderTaskUtils<nodes::Type> { struct TypeBuilderTaskBase : public BuilderTaskUtils<nodes::Type> {
using BuilderTaskUtils<nodes::Type>::BuilderTaskUtils; using BuilderTaskUtils<nodes::Type>::BuilderTaskUtils;
template <typename OtherN, typename OtherTag = utils::None, template <typename OtherN, typename OtherTag = core::None,
typename Ret = nodes::Type> typename Ret = nodes::Type>
Ret Run(const parser::ParseTree::Node &node, const Args &args = {}) { Ret Run(const parser::ParseTree::Node &node, const Args &args = {}) {
BuilderTask<OtherN, OtherTag> task(this->executor); BuilderTask<OtherN, OtherTag> task(this->executor);
@ -111,7 +111,7 @@ template <typename N>
struct StatementBuilderTaskBase : public BuilderTaskUtils<N> { struct StatementBuilderTaskBase : public BuilderTaskUtils<N> {
using BuilderTaskUtils<N>::BuilderTaskUtils; using BuilderTaskUtils<N>::BuilderTaskUtils;
template <typename OtherN, typename OtherTag = utils::None, template <typename OtherN, typename OtherTag = core::None,
typename Ret = OtherN> typename Ret = OtherN>
Ret Run(const parser::ParseTree::Node &node, const Args &args = {}) { Ret Run(const parser::ParseTree::Node &node, const Args &args = {}) {
BuilderTask<OtherN, OtherTag> task(this->executor); BuilderTask<OtherN, OtherTag> task(this->executor);

View file

@ -180,8 +180,8 @@ struct BuilderTask<nodes::ModifierExpression, T>
return Build( return Build(
nodes::ModifierExpression{ nodes::ModifierExpression{
.modifier = RunOther<nodes::Modifier, utils::None, nodes::Modifier>( .modifier =
parser_node.nth_child(modifier_pos)), RunOther<nodes::Modifier>(parser_node.nth_child(modifier_pos)),
.expr = Run<Node>(parser_node.nth_named_child(0)), .expr = Run<Node>(parser_node.nth_named_child(0)),
}, },
parser_node.get_pos()); parser_node.get_pos());

View file

@ -8,7 +8,7 @@
#include "type_builders.hpp" #include "type_builders.hpp"
#include "type_nodes.hpp" #include "type_nodes.hpp"
// TODO: insert is_scoped everywere // TODO: insert is_scoped assignment everywere
namespace builders { namespace builders {
@ -134,10 +134,9 @@ Node BuilderTask<Node>::operator()(const ParserNode &parser_node,
return Build(RunOther<nodes::Literal, nodes::null>(parser_node), return Build(RunOther<nodes::Literal, nodes::null>(parser_node),
parser_node.get_pos()); parser_node.get_pos());
case tokens::Type::EXTRA: case tokens::Type::EXTRA:
return Build(RunOther<nodes::Extra, utils::None>(parser_node), return Build(RunOther<nodes::Extra>(parser_node), parser_node.get_pos());
parser_node.get_pos());
case tokens::Type::EMPTY_LINES: case tokens::Type::EMPTY_LINES:
return Build(RunOther<nodes::EmptyLines, utils::None>(parser_node), return Build(RunOther<nodes::EmptyLines>(parser_node),
parser_node.get_pos()); parser_node.get_pos());
default: default:
break; break;
@ -370,8 +369,7 @@ Node BuilderTask<nodes::NameDefinition>::operator()(
.kind = (modifier == "%" || modifier == "let") .kind = (modifier == "%" || modifier == "let")
? nodes::NameDefinition::LET ? nodes::NameDefinition::LET
: nodes::NameDefinition::VAR, : nodes::NameDefinition::VAR,
.name = .name = RunOther<nodes::Identifier>(name_node),
Run<nodes::Identifier, utils::None, nodes::Identifier>(name_node),
}, },
parser_node.get_pos()); parser_node.get_pos());
} // IN PROGRESS } // IN PROGRESS
@ -487,8 +485,7 @@ Node BuilderTask<nodes::NameExpression, utils::FuncCallTag>::operator()(
.name = RunOther<nodes::Identifier>(name_node), .name = RunOther<nodes::Identifier>(name_node),
.args = std::move(args), .args = std::move(args),
.prefix = prefix_node.has_value() .prefix = prefix_node.has_value()
? RunOther<nodes::Type, utils::None, nodes::Type>( ? RunOther<nodes::Type>(prefix_node.value())
prefix_node.value())
: nodes::MaybeType(), : nodes::MaybeType(),
.is_point_call = is_point_call, .is_point_call = is_point_call,
.is_operator_call = false, .is_operator_call = false,
@ -512,8 +509,8 @@ Node BuilderTask<nodes::Constructor>::operator()(const ParserNode &parser_node,
return Build( return Build(
nodes::Constructor{ nodes::Constructor{
.type = RunOther<nodes::Type, utils::None, nodes::Type>( .type =
parser_node.child_by_field_name("type")), RunOther<nodes::Type>(parser_node.child_by_field_name("type")),
.args = std::move(args), .args = std::move(args),
}, },
parser_node.get_pos()); parser_node.get_pos());

View file

@ -239,10 +239,9 @@ BuilderTask<nodes::TypeDefinition>::operator()(const ParserNode &parser_node,
} }
} }
nodes::MaybeType type = nodes::MaybeType type = type_node.has_value()
type_node.has_value() ? RunOther<nodes::Type>(type_node.value())
? RunOther<nodes::Type, utils::None, nodes::Type>(type_node.value()) : nodes::MaybeType();
: nodes::MaybeType();
std::unordered_set<std::string> annotations; std::unordered_set<std::string> annotations;
@ -378,14 +377,12 @@ nodes::FunctionDefinition BuilderTask<nodes::FunctionDefinition>::operator()(
case tokens::Type::SIMPLE_TYPE: case tokens::Type::SIMPLE_TYPE:
if (current_type_id >= args.size()) { if (current_type_id >= args.size()) {
args.push_back(nodes::FunctionDefinition::Argument( args.push_back(nodes::FunctionDefinition::Argument(
last_annotation, last_annotation, RunOther<nodes::Type>(current_node),
RunOther<nodes::Type, utils::None, nodes::Type>(current_node),
last_before_modifier)); last_before_modifier));
} else { } else {
if (!args[current_type_id].add_type( if (!args[current_type_id].add_type(last_annotation,
last_annotation, RunOther<nodes::Type>(current_node),
RunOther<nodes::Type, utils::None, nodes::Type>(current_node), last_before_modifier)) {
last_before_modifier)) {
logc.Fatal<Log::kProc>( logc.Fatal<Log::kProc>(
{{"It is impossible to use argument modifiers (annotations, " {{"It is impossible to use argument modifiers (annotations, "
"references, " "references, "

View file

@ -103,9 +103,7 @@ nodes::Type BuilderTask<nodes::Type, TypeTag<Tp::REFERENCE_TYPE>>::operator()(
Log::Context logc(executor.log(), Log::Area::kParse); Log::Context logc(executor.log(), Log::Area::kParse);
nodes::Type type = Run<nodes::Type>(parser_node.nth_named_child(0)); nodes::Type type = Run<nodes::Type>(parser_node.nth_named_child(0));
type.get()->set_modifier( type.get()->set_modifier(RunOther<nodes::Modifier>(parser_node.nth_child(0)));
RunOther<nodes::Modifier, utils::None, nodes::Modifier>(
parser_node.nth_child(0)));
return type; return type;
} }
@ -117,9 +115,8 @@ nodes::Type BuilderTask<nodes::Type, TypeTag<Tp::MODIFIED_TYPE>>::operator()(
std::vector<nodes::Type> parameters; std::vector<nodes::Type> parameters;
parameters.push_back(Run<nodes::Type>(parser_node.nth_named_child(0))); parameters.push_back(Run<nodes::Type>(parser_node.nth_named_child(0)));
nodes::Modifier modifier = nodes::Modifier modifier = RunOther<nodes::Modifier>(
RunOther<nodes::Modifier, utils::None, nodes::Modifier>( parser_node.nth_child(parser_node.child_count() - 1));
parser_node.nth_child(parser_node.child_count() - 1));
std::string identifier; std::string identifier;
@ -153,8 +150,7 @@ nodes::Type BuilderTask<nodes::Type, TypeTag<Tp::SIMPLE_TYPE>>::operator()(
collect_parameters(name_node.next_named_sibling(), executor); collect_parameters(name_node.next_named_sibling(), executor);
return executor.state<Types>().add_type(nodes::TypeData( return executor.state<Types>().add_type(nodes::TypeData(
RunOther<nodes::Identifier, utils::None, nodes::Identifier>(name_node), RunOther<nodes::Identifier>(name_node), std::move(parameters)));
std::move(parameters)));
} }
} // namespace builders } // namespace builders

View file

@ -125,7 +125,7 @@ private:
using Exprs = nodes::NodeStorage; // nodes::ExprStorage; using Exprs = nodes::NodeStorage; // nodes::ExprStorage;
using Executor = utils::Executor<Exprs, Printer>; using Executor = core::Executor<Exprs, Printer>;
using Node = nodes::Node_<>; using Node = nodes::Node_<>;
@ -134,9 +134,9 @@ struct Args {
bool const_is_none = false; bool const_is_none = false;
}; };
using Result = utils::None; using Result = core::None;
template <typename N> using Task = utils::Task<Executor, Result, Args, N>; template <typename N> using Task = core::Task<Executor, Result, Args, N>;
template <typename N> struct PrintTask { template <typename N> struct PrintTask {
static_assert(false); static_assert(false);

View file

@ -165,7 +165,7 @@ using Types = nodes::TypeStorage;
using Names = names::NameTree; using Names = names::NameTree;
using Positions = core::DependentStorage<utils::Pos>; using Positions = core::DependentStorage<utils::Pos>;
using Executor = utils::Executor<Exprs, Types, Names, State, Positions>; using Executor = core::Executor<Exprs, Types, Names, State, Positions>;
using Node = nodes::Node_<nodes::NodePart<utils::Pos>>; using Node = nodes::Node_<nodes::NodePart<utils::Pos>>;
@ -350,7 +350,7 @@ void type_check_error(const std::string &message, const utils::Pos &pos,
// //
template <typename N> using Task = utils::Task<Executor, Result, Args, N>; template <typename N> using Task = core::Task<Executor, Result, Args, N>;
template <typename N> struct CheckTask { template <typename N> struct CheckTask {
static_assert(false); static_assert(false);

View file

@ -2,7 +2,7 @@
#include "log.hpp" #include "log.hpp"
namespace utils { namespace core {
struct None {}; struct None {};
@ -74,4 +74,4 @@ public:
Exec &executor; Exec &executor;
}; };
} // namespace utils } // namespace core

View file

@ -1 +1,3 @@
#include "executor.hpp" #include "executor.hpp"
namespace core {} // namespace core