Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Обновление Visitor.NET #69

Merged
merged 2 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ let s = v2d as string
После клонирования репозитория идём в папку проекта `HydraScript`.

Там выполняем команду:
```dotnet publish -r <RUNTIME_IDENTIFIER> -p:PublishSingleFile=true -p:DebugType=embedded --self-contained false -o <OUTPUT_DIRECTORY>```
```dotnet publish ./src/HydraScript/HydraScript.csproj -r <RUNTIME_IDENTIFIER> -p:PublishSingleFile=true -p:DebugType=embedded --self-contained false -o <OUTPUT_DIRECTORY>```

Список идентификаторов рантайма лежит [тут](https://docs.microsoft.com/en-us/dotnet/core/rid-catalog#windows-rids)

Expand Down
2 changes: 1 addition & 1 deletion src/HydraScript.Lib/FrontEnd/GetTokens/Data/Token.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public override string ToString()

public record EndToken() : Token(new EndOfProgramType(), null!, null!)
{
public override string ToString() => Type.ToString();
public override string ToString() => Type.Tag;
}

[ExcludeFromCodeCoverage]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ public record TokenType(string Tag, string Pattern, int Priority)

public string GetNamedRegex() => $"(?<{Tag}>{Pattern})";

public sealed override string ToString() => Tag;
public override string ToString() => Tag;
}
3 changes: 2 additions & 1 deletion src/HydraScript.Lib/HydraScript.Lib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Visitor.NET" Version="3.0.0" />
<PackageReference Include="Visitor.NET" Version="4.1.1" />
<PackageReference Include="Visitor.NET.AutoVisitableGen" Version="1.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
31 changes: 5 additions & 26 deletions src/HydraScript.Lib/IR/Ast/AbstractSyntaxTreeNode.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
using System.Collections;
using HydraScript.Lib.BackEnd;
using HydraScript.Lib.FrontEnd.GetTokens.Data;
using HydraScript.Lib.IR.Ast.Visitors;
using HydraScript.Lib.IR.CheckSemantics.Variables;
using HydraScript.Lib.IR.CheckSemantics.Visitors;

namespace HydraScript.Lib.IR.Ast;

public abstract class AbstractSyntaxTreeNode : IEnumerable<AbstractSyntaxTreeNode>,
IVisitable<InstructionProvider, AddressedInstructions>,
IVisitable<SemanticChecker, Type>,
IVisitable<SymbolTableInitializer>,
IVisitable<TypeSystemLoader>,
IVisitable<DeclarationVisitor>
public abstract class AbstractSyntaxTreeNode :
IEnumerable<AbstractSyntaxTreeNode>,
IVisitable<AbstractSyntaxTreeNode>
{
public AbstractSyntaxTreeNode? Parent { get; set; }

Expand Down Expand Up @@ -55,23 +49,8 @@ public bool ChildOf<T>() where T : AbstractSyntaxTreeNode
IEnumerator IEnumerable.GetEnumerator() =>
GetEnumerator();

#region Visitors

public virtual Unit Accept(SymbolTableInitializer visitor) =>
visitor.Visit(this);

public virtual Unit Accept(TypeSystemLoader visitor) =>
visitor.Visit(this);

public virtual Unit Accept(DeclarationVisitor visitor) =>
visitor.Visit(this);

public virtual Type Accept(SemanticChecker visitor) =>
"undefined";

public abstract AddressedInstructions Accept(InstructionProvider visitor);

#endregion
public virtual TReturn Accept<TReturn>(IVisitor<AbstractSyntaxTreeNode, TReturn> visitor) =>
visitor.DefaultVisit;

protected abstract string NodeRepresentation();

Expand Down
10 changes: 5 additions & 5 deletions src/HydraScript.Lib/IR/Ast/Impl/AbstractSyntaxTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ public class AbstractSyntaxTree : IAbstractSyntaxTree
{
private readonly AbstractSyntaxTreeNode _root;

private readonly SymbolTableInitializer _symbolTableInitializer;
private readonly TypeSystemLoader _typeSystemLoader;
private readonly DeclarationVisitor _declarationVisitor;
private readonly IVisitor<AbstractSyntaxTreeNode> _symbolTableInitializer;
private readonly IVisitor<AbstractSyntaxTreeNode> _typeSystemLoader;
private readonly IVisitor<AbstractSyntaxTreeNode> _declarationVisitor;

private readonly SemanticChecker _semanticChecker;
private readonly InstructionProvider _instructionProvider;
private readonly IVisitor<AbstractSyntaxTreeNode, Type> _semanticChecker;
private readonly IVisitor<AbstractSyntaxTreeNode, AddressedInstructions> _instructionProvider;

public AbstractSyntaxTree(AbstractSyntaxTreeNode root)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using HydraScript.Lib.IR.CheckSemantics.Visitors;

namespace HydraScript.Lib.IR.Ast.Impl.Nodes.Declarations.AfterTypesAreLoaded;

public abstract class AfterTypesAreLoadedDeclaration : Declaration
{
public abstract override Unit Accept(DeclarationVisitor visitor);
public abstract override TReturn Accept<TReturn>(
IVisitor<AbstractSyntaxTreeNode, TReturn> visitor);
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using HydraScript.Lib.BackEnd;
using HydraScript.Lib.IR.Ast.Impl.Nodes.Expressions.PrimaryExpressions;
using HydraScript.Lib.IR.Ast.Impl.Nodes.Statements;
using HydraScript.Lib.IR.Ast.Visitors;
using HydraScript.Lib.IR.CheckSemantics.Visitors;

namespace HydraScript.Lib.IR.Ast.Impl.Nodes.Declarations.AfterTypesAreLoaded;

public class FunctionDeclaration : AfterTypesAreLoadedDeclaration
[AutoVisitable<AbstractSyntaxTreeNode>]
public partial class FunctionDeclaration : AfterTypesAreLoadedDeclaration
{
private IReadOnlyCollection<ReturnStatement>? _returnStatements;

Expand Down Expand Up @@ -48,16 +46,4 @@ public override IEnumerator<AbstractSyntaxTreeNode> GetEnumerator()

protected override string NodeRepresentation() =>
"function " + Name;

public override Unit Accept(SymbolTableInitializer visitor) =>
visitor.Visit(this);

public override Unit Accept(DeclarationVisitor visitor) =>
visitor.Visit(this);

public override Type Accept(SemanticChecker visitor) =>
visitor.Visit(this);

public override AddressedInstructions Accept(InstructionProvider visitor) =>
visitor.Visit(this);
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
using HydraScript.Lib.BackEnd;
using HydraScript.Lib.IR.Ast.Impl.Nodes.Expressions;
using HydraScript.Lib.IR.Ast.Visitors;
using HydraScript.Lib.IR.CheckSemantics.Visitors;

namespace HydraScript.Lib.IR.Ast.Impl.Nodes.Declarations.AfterTypesAreLoaded;

public class LexicalDeclaration : AfterTypesAreLoadedDeclaration
[AutoVisitable<AbstractSyntaxTreeNode>]
public partial class LexicalDeclaration(bool readOnly) : AfterTypesAreLoadedDeclaration
{
public bool ReadOnly { get; }
public List<AssignmentExpression> Assignments { get; }

public LexicalDeclaration(bool readOnly)
{
ReadOnly = readOnly;
Assignments = new();
}
public bool ReadOnly { get; } = readOnly;
public List<AssignmentExpression> Assignments { get; } = [];

public void AddAssignment(AssignmentExpression assignment)
{
Expand All @@ -27,13 +19,4 @@ public override IEnumerator<AbstractSyntaxTreeNode> GetEnumerator() =>

protected override string NodeRepresentation() =>
ReadOnly ? "const" : "let";

public override Unit Accept(DeclarationVisitor visitor) =>
visitor.Visit(this);

public override Type Accept(SemanticChecker visitor) =>
visitor.Visit(this);

public override AddressedInstructions Accept(InstructionProvider visitor) =>
visitor.Visit(this);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using HydraScript.Lib.BackEnd;
using HydraScript.Lib.IR.Ast.Impl.Nodes.Expressions.PrimaryExpressions;
using HydraScript.Lib.IR.Ast.Visitors;
using HydraScript.Lib.IR.CheckSemantics.Visitors;

namespace HydraScript.Lib.IR.Ast.Impl.Nodes.Declarations;

public class TypeDeclaration : Declaration
[AutoVisitable<AbstractSyntaxTreeNode>]
public partial class TypeDeclaration : Declaration
{
private readonly TypeValue _typeValue;
public IdentifierReference TypeId { get; }
Expand All @@ -26,9 +24,4 @@ public override IEnumerator<AbstractSyntaxTreeNode> GetEnumerator()

protected override string NodeRepresentation() =>
$"type {TypeId.Name} = {_typeValue}";

public override AddressedInstructions Accept(InstructionProvider visitor) => new();

public override Unit Accept(TypeSystemLoader visitor) =>
visitor.Visit(this);
}
17 changes: 5 additions & 12 deletions src/HydraScript.Lib/IR/Ast/Impl/Nodes/Declarations/TypeValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ public abstract record TypeValue
public abstract Type BuildType(SymbolTable symbolTable);
}

public record TypeIdentValue(
IdentifierReference TypeId
) : TypeValue
public record TypeIdentValue(IdentifierReference TypeId) : TypeValue
{
public override Type BuildType(SymbolTable symbolTable) =>
symbolTable.FindSymbol<TypeSymbol>(TypeId)?.Type ??
Expand All @@ -22,19 +20,15 @@ public override Type BuildType(SymbolTable symbolTable) =>
public override string ToString() => TypeId;
}

public record ArrayTypeValue(
TypeValue TypeValue
) : TypeValue
public record ArrayTypeValue(TypeValue TypeValue) : TypeValue
{
public override Type BuildType(SymbolTable symbolTable) =>
new ArrayType(TypeValue.BuildType(symbolTable));

public override string ToString() => $"{TypeValue}[]";
}

public record NullableTypeValue(
TypeValue TypeValue
) : TypeValue
public record NullableTypeValue(TypeValue TypeValue) : TypeValue
{
public override Type BuildType(SymbolTable symbolTable) =>
new NullableType(TypeValue.BuildType(symbolTable));
Expand All @@ -48,11 +42,10 @@ public record PropertyTypeValue(
{
public override string ToString() =>
$"{Key}: {TypeValue}";
};
}

public record ObjectTypeValue(
IEnumerable<PropertyTypeValue> Properties
) : TypeValue
IEnumerable<PropertyTypeValue> Properties) : TypeValue
{
public override Type BuildType(SymbolTable symbolTable) =>
new ObjectType(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using HydraScript.Lib.IR.CheckSemantics.Visitors;

namespace HydraScript.Lib.IR.Ast.Impl.Nodes.Expressions.AccessExpressions;

public abstract class AccessExpression : Expression
Expand All @@ -26,5 +24,6 @@ public bool HasNext() =>
public bool HasPrev() =>
Prev is not null;

public abstract override Type Accept(SemanticChecker visitor);
public abstract override TReturn Accept<TReturn>(
IVisitor<AbstractSyntaxTreeNode, TReturn> visitor);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using HydraScript.Lib.BackEnd;
using HydraScript.Lib.IR.Ast.Impl.Nodes.Expressions.PrimaryExpressions;
using HydraScript.Lib.IR.Ast.Visitors;
using HydraScript.Lib.IR.CheckSemantics.Visitors;

namespace HydraScript.Lib.IR.Ast.Impl.Nodes.Expressions.AccessExpressions;

public class DotAccess : AccessExpression
[AutoVisitable<AbstractSyntaxTreeNode>]
public partial class DotAccess : AccessExpression
{
public IdentifierReference Property { get; }

Expand All @@ -25,10 +23,4 @@ public override IEnumerator<AbstractSyntaxTreeNode> GetEnumerator()
}

protected override string NodeRepresentation() => ".";

public override Type Accept(SemanticChecker visitor) =>
visitor.Visit(this);

public override AddressedInstructions Accept(ExpressionInstructionProvider visitor) =>
visitor.Visit(this);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using HydraScript.Lib.BackEnd;
using HydraScript.Lib.IR.Ast.Visitors;
using HydraScript.Lib.IR.CheckSemantics.Visitors;

namespace HydraScript.Lib.IR.Ast.Impl.Nodes.Expressions.AccessExpressions;

public class IndexAccess : AccessExpression
[AutoVisitable<AbstractSyntaxTreeNode>]
public partial class IndexAccess : AccessExpression
{
public Expression Index { get; }

Expand All @@ -24,10 +21,4 @@ public override IEnumerator<AbstractSyntaxTreeNode> GetEnumerator()
}

protected override string NodeRepresentation() => "[]";

public override Type Accept(SemanticChecker visitor) =>
visitor.Visit(this);

public override AddressedInstructions Accept(ExpressionInstructionProvider visitor) =>
visitor.Visit(this);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using HydraScript.Lib.BackEnd;
using HydraScript.Lib.IR.Ast.Impl.Nodes.Declarations;
using HydraScript.Lib.IR.Ast.Visitors;
using HydraScript.Lib.IR.CheckSemantics.Visitors;

namespace HydraScript.Lib.IR.Ast.Impl.Nodes.Expressions;

public class AssignmentExpression : Expression
[AutoVisitable<AbstractSyntaxTreeNode>]
public partial class AssignmentExpression : Expression
{
public LeftHandSideExpression Destination { get; }
public Expression Source { get; }
Expand All @@ -32,10 +30,4 @@ public override IEnumerator<AbstractSyntaxTreeNode> GetEnumerator()
}

protected override string NodeRepresentation() => "=";

public override Type Accept(SemanticChecker visitor) =>
visitor.Visit(this);

public override AddressedInstructions Accept(ExpressionInstructionProvider visitor) =>
visitor.Visit(this);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using HydraScript.Lib.BackEnd;
using HydraScript.Lib.IR.Ast.Visitors;
using HydraScript.Lib.IR.CheckSemantics.Visitors;

namespace HydraScript.Lib.IR.Ast.Impl.Nodes.Expressions;

public class BinaryExpression : Expression
[AutoVisitable<AbstractSyntaxTreeNode>]
public partial class BinaryExpression : Expression
{
public Expression Left { get; }
public string Operator { get; }
Expand All @@ -28,10 +25,4 @@ public override IEnumerator<AbstractSyntaxTreeNode> GetEnumerator()
}

protected override string NodeRepresentation() => Operator;

public override Type Accept(SemanticChecker visitor) =>
visitor.Visit(this);

public override AddressedInstructions Accept(ExpressionInstructionProvider visitor) =>
visitor.Visit(this);
}
Loading
Loading