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

238329
src/parser.c

File diff suppressed because it is too large Load diff