interpreter_tree fixed

This commit is contained in:
ProgramSnail 2023-04-25 13:22:23 +03:00
parent 1289dda838
commit 2ff2f3af12
2 changed files with 123245 additions and 115166 deletions

View file

@ -56,7 +56,7 @@ using SourceStatement = std::variant<
// Definition parts // Definition parts
using ImportSymbol = AnyIdentifier; using ImportSymbol = AnyIdentifier; // can be extended name
struct FunctionDefinition; struct FunctionDefinition;
struct TypeDefinition; struct TypeDefinition;
@ -69,6 +69,8 @@ using AnyAnnotatedType = AnnotatedType;
// Flow control ----------------- // Flow control -----------------
struct TypeConstructorPattern;
struct Match; struct Match;
struct Condition; struct Condition;
struct DoWhileLoop; struct DoWhileLoop;
@ -117,7 +119,6 @@ using SubExpression = std::variant<
std::unique_ptr<FunctionCallExpression>, std::unique_ptr<FunctionCallExpression>,
std::unique_ptr<BinaryOperatorExpression>, std::unique_ptr<BinaryOperatorExpression>,
std::unique_ptr<SubExpressionToken>, std::unique_ptr<SubExpressionToken>,
std::unique_ptr<ArrayExpression>,
std::unique_ptr<ReferenceExpression>>; std::unique_ptr<ReferenceExpression>>;
// //
enum class LoopControlExpression { enum class LoopControlExpression {
@ -147,6 +148,7 @@ using SuperExpression = std::variant<
std::unique_ptr<FlowControl>, std::unique_ptr<FlowControl>,
std::unique_ptr<TupleExpression>, std::unique_ptr<TupleExpression>,
std::unique_ptr<VariantExpression>, std::unique_ptr<VariantExpression>,
std::unique_ptr<ArrayExpression>,
std::unique_ptr<Expression>>; std::unique_ptr<Expression>>;
// //
@ -191,14 +193,14 @@ using ScopedAnyName = AnyName;
struct FunctionType; struct FunctionType;
struct TupleType; struct TupleType;
struct VariantType; struct VariantType;
struct ParametrizedType; struct TypeExpression;
struct TypeExpression; struct TypeExpression;
using Constructor = std::string; using Constructor = std::string;
// // ScopedAnyType <-> AnyType // // ScopedAnyType <-> AnyType
using AnyType = std::variant< using AnyType = std::variant<
std::unique_ptr<ParametrizedType>, std::unique_ptr<TypeExpression>,
std::unique_ptr<TupleType>, std::unique_ptr<TupleType>,
std::unique_ptr<VariantType>, std::unique_ptr<VariantType>,
std::unique_ptr<FunctionType>>; std::unique_ptr<FunctionType>>;
@ -212,15 +214,13 @@ struct ExtendedScopedAnyType;
struct ParametrizedTypeclass; struct ParametrizedTypeclass;
struct TypeclassExpression; struct TypeclassExpression;
using TypeclassUsage = std::variant< using TypeclassSubExpression = std::variant<
std::unique_ptr<TypeclassExpression>, std::unique_ptr<TypeclassIdentifier>,
std::unique_ptr<ParametrizedTypeclass>>; std::unique_ptr<ParametrizedTypeclass>>;
// Typeclass & Type // Typeclass & Type
using TypeParameter = std::variant< struct ParametrizedType;
std::unique_ptr<TypeExpression>,
std::unique_ptr<ParametrizedType>>;
using TypeSubExpression = std::variant< using TypeSubExpression = std::variant<
std::unique_ptr<AnyTypeIdentifier>, std::unique_ptr<AnyTypeIdentifier>,
@ -239,6 +239,16 @@ struct ExtendedName {
std::string name; std::string name;
}; };
using PatternToken = std::variant<
std::unique_ptr<ExtendedName>,
std::unique_ptr<Literal>,
std::unique_ptr<TypeConstructorPattern>>;
using Pattern = std::variant<
std::unique_ptr<TypeConstructorPattern>,
std::unique_ptr<PatternToken>>;
//////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////
// ----------------- Sources ----------------- // ----------------- Sources -----------------
@ -289,7 +299,7 @@ struct AliasDefinitionStatement {
enum {Alias, Type, Let} modifier; enum {Alias, Type, Let} modifier;
TypeIdentifier type; TypeIdentifier type;
std::vector<AbstractTypeIdentifier> parameters; std::vector<AbstractTypeIdentifier> parameters;
std::unique_ptr<ParametrizedType> value; std::unique_ptr<TypeExpression> value;
std::vector<utils::IdType> parameter_graph_ids_; std::vector<utils::IdType> parameter_graph_ids_;
utils::IdType type_id_; utils::IdType type_id_;
@ -303,7 +313,7 @@ struct VariableDefinitionStatement {
}; };
struct FunctionDeclaration { struct FunctionDeclaration {
NameOrOperatorIdentifier name; ExtendedName name;
std::vector<std::unique_ptr<AnnotatedAbstractType>> parameters; std::vector<std::unique_ptr<AnnotatedAbstractType>> parameters;
std::unique_ptr<FunctionType> type; std::unique_ptr<FunctionType> type;
@ -347,7 +357,7 @@ struct TypeclassDefinitionStatement {
struct FunctionDefinition { struct FunctionDefinition {
enum { Operator, Function } modifier; enum { Operator, Function } modifier;
NameOrOperatorIdentifier name; ExtendedName name;
std::vector<std::unique_ptr<AnnotatedAbstractType>> parameters; std::vector<std::unique_ptr<AnnotatedAbstractType>> parameters;
std::vector<ExtendedName> arguments; std::vector<ExtendedName> arguments;
}; };
@ -359,15 +369,20 @@ struct TypeDefinition {
struct AnnotatedAbstractType { struct AnnotatedAbstractType {
AbstractTypeIdentifier type; AbstractTypeIdentifier type;
std::vector<TypeclassUsage> typeclasses; std::vector<TypeclassExpression> typeclasses;
utils::IdType type_graph_id_; utils::IdType type_graph_id_;
}; };
// ----------------- Flow control ----------------- // ----------------- Flow control -----------------
struct TypeConstructorPattern {
TypeIdentifier constructor;
std::vector<std::pair<std::optional<ExtendedName>, PatternToken>> parameters;
};
struct MatchCase { struct MatchCase {
Expression value; Pattern value;
std::optional<Expression> condition; std::optional<Expression> condition;
std::optional<Expression> statement; std::optional<Expression> statement;
}; };
@ -444,7 +459,8 @@ struct AccessExpression {
// Other Expressions ----------------- // Other Expressions -----------------
struct FunctionCallExpression { struct FunctionCallExpression {
std::unique_ptr<NameExpression> name; std::unique_ptr<std::variant<SubExpressionToken, TypeExpression>> prefix;
ExtendedName name;
std::vector<FunctionArgument> arguments; std::vector<FunctionArgument> arguments;
}; };
@ -462,8 +478,8 @@ struct ReturnExpression {
struct TypeConstructor { struct TypeConstructor {
enum AssignmentModifier { Move, Assign }; enum AssignmentModifier { Move, Assign };
std::unique_ptr<ParametrizedType> type; std::unique_ptr<TypeExpression> constructor;
std::vector<std::tuple<ExtendedName, AssignmentModifier, SubExpression>> parameters; std::vector<std::pair<std::optional<std::pair<ExtendedName, AssignmentModifier>>, SubExpression>> parameters;
}; };
struct LambdaFunction { struct LambdaFunction {
@ -476,14 +492,13 @@ struct LambdaFunction {
}; };
struct ArrayExpression { struct ArrayExpression {
std::vector<Expression> elements; std::vector<SubExpression> elements;
}; };
// Name ----------------- // Name -----------------
struct NameExpression { struct NameExpression {
std::vector<TypeSubExpression> namespaces; std::vector<ExtendedName> names;
std::vector<ExtendedName> expressions;
}; };
struct TupleName { struct TupleName {
@ -517,14 +532,8 @@ struct VariantType {
std::vector<std::variant<Constructor, std::unique_ptr<TupleType>>> constructors; std::vector<std::variant<Constructor, std::unique_ptr<TupleType>>> constructors;
}; };
struct ParametrizedType {
std::unique_ptr<TypeExpression> type_expression;
std::vector<TypeParameter> parameters;
};
struct TypeExpression { struct TypeExpression {
std::vector<TypeSubExpression> namespaces; std::vector<TypeSubExpression> types;
AnyTypeIdentifier type;
std::optional<size_t> array_size; // if array; 0 - dynamic size std::optional<size_t> array_size; // if array; 0 - dynamic size
utils::IdType type_id_; utils::IdType type_id_;
@ -537,18 +546,25 @@ struct ExtendedScopedAnyType {
// Typeclass ----------------- // Typeclass -----------------
struct ParametrizedTypeclass {
std::unique_ptr<TypeclassExpression> typeclass_expression;
std::vector<TypeParameter> parameters;
};
struct TypeclassExpression { struct TypeclassExpression {
std::vector<TypeSubExpression> namespaces; std::vector<TypeSubExpression> namespaces;
TypeclassIdentifier typeclass; TypeclassSubExpression typeclass;
utils::IdType type_id_; utils::IdType type_id_;
}; };
struct ParametrizedTypeclass {
TypeclassIdentifier typeclass_expression;
std::vector<TypeExpression> parameters;
};
// Typeclass & Type -----------------
struct ParametrizedType {
AnyTypeIdentifier type_expression;
std::vector<TypeExpression> parameters;
};
// ----------------- Comments [IGNORE] ----------------- // ----------------- Comments [IGNORE] -----------------
// ----------------- Identifiers, constants, etc. ----------------- // ----------------- Identifiers, constants, etc. -----------------

238329
src/parser.c

File diff suppressed because it is too large Load diff