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

Рефакторинг доменной модели #10

Merged
merged 56 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
19ab223
Переезд на .net 6
Stepami Sep 9, 2022
4bac666
рефакторинг модели типа токена
Stepami Sep 9, 2022
87e8bff
обновление пайплайнов в связи с переездом на новый .NET
Stepami Sep 9, 2022
147afcf
Update Readme.md
Stepami Sep 9, 2022
9ee051c
update version
Stepami Sep 9, 2022
7d0b232
перенос DoubleValueConverter в тело инструкции, поскольку он использу…
Stepami Sep 9, 2022
295c556
Черновик контрактов front-end'а интерпретатора
Stepami Sep 10, 2022
5e3176c
каркас сущности для внутренностей парсера
Stepami Sep 10, 2022
a09bc1f
реорганизация папок
Stepami Sep 12, 2022
5228244
переименование папок по принципу feature directory
Stepami Sep 12, 2022
8d3c28f
В рамках проектирования модели создан контекст FrontEnd, где находятс…
Stepami Sep 12, 2022
3a35d78
bugfix
Stepami Sep 12, 2022
f723a80
небольшое форматтирование
Stepami Sep 12, 2022
78b9a81
bugfix
Stepami Sep 12, 2022
4e8a375
небольшие инфраструктурные изменения: поскольку теперь сущности интер…
Stepami Sep 12, 2022
3513f22
suppressing possible NRE using language feature
Stepami Sep 12, 2022
862d7e6
Подстроил инфраструктуру под использование новых доменных контрактов
Stepami Sep 12, 2022
cdb061c
доработка контрактов доменной модели
Stepami Sep 12, 2022
53d19fc
удалил неиспользуемый класс
Stepami Sep 12, 2022
b43aa04
Выпилил всё, что связано с оптимизацией
Stepami Sep 12, 2022
a3bab8c
Применил паттерн Декоратор для реализация логгируемых сущностей
Stepami Sep 12, 2022
e054ae0
переместил логгируемые сущности в инфраструктуру, так как, по сути он…
Stepami Sep 12, 2022
32ac26e
маштабная реорганизация файлов - 3 верхнеуровневых контекста:
Stepami Sep 14, 2022
77ba1d4
solution rename
Stepami Sep 14, 2022
7a5a2e4
Спецификация категории тестов
Stepami Sep 14, 2022
608c69e
Небольшой рефакторинг бэкенда
Stepami Sep 14, 2022
85b4d6c
removed unused usings
Stepami Sep 14, 2022
0270e3d
рефакторинг ошибок семантики
Stepami Sep 14, 2022
bf62482
повысил порог coverage до 80%
Stepami Sep 14, 2022
35b9faf
рефакторинг печати в виртуальной машине
Stepami Sep 15, 2022
04d1ff6
реорганизация папок фичи GetTokens
Stepami Sep 15, 2022
81750d8
реорганизация бэкенда
Stepami Sep 15, 2022
5045e3a
рефакторинг модели символов и использованием ковариантных вохвращаемы…
Stepami Sep 15, 2022
da45269
lexer tests
Stepami Sep 15, 2022
ef086a9
fix tests
Stepami Sep 15, 2022
66f81f3
more lexer tests
Stepami Sep 15, 2022
fd7d472
StructureTests.cs
Stepami Sep 15, 2022
ad7e2f7
реорганизация папок в тестах
Stepami Sep 15, 2022
8ed2163
vm tests
Stepami Sep 15, 2022
f123244
more vm tests
Stepami Sep 15, 2022
7fe49a2
vm tests refactoring
Stepami Sep 15, 2022
75fad81
factorial unit test
Stepami Sep 15, 2022
b8f7227
Instruction.cs refactoring
Stepami Sep 15, 2022
ae6e02a
coverage
Stepami Sep 15, 2022
85b7970
values tests
Stepami Sep 15, 2022
88bae13
coverage
Stepami Sep 15, 2022
742a5bc
coverage
Stepami Sep 15, 2022
9c554a5
coverage
Stepami Sep 15, 2022
a7784a8
fix Readme.md
Stepami Sep 15, 2022
925c58a
rename file
Stepami Sep 15, 2022
da1709a
Instructions tests
Stepami Sep 15, 2022
db3c387
test suffix
Stepami Sep 15, 2022
89bcad5
coverage
Stepami Sep 15, 2022
b39aeb4
removed unused
Stepami Sep 15, 2022
aaa2c6c
exception guidelines https://docs.microsoft.com/en-us/dotnet/csharp/f…
Stepami Sep 15, 2022
f5c850c
infrastructure coverage
Stepami Sep 15, 2022
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
8 changes: 4 additions & 4 deletions .github/workflows/develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 5.0.x
dotnet-version: 6.0.x
- name: Cache NuGet packages
uses: actions/cache@v3
with:
Expand All @@ -29,14 +29,14 @@ jobs:
- name: Build
run: dotnet build --no-restore -c Release -v n
- name: Test
run: dotnet test -c Release --no-build -v n /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura
run: dotnet test -c Release --no-build -v n /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura --filter="Category=Unit"
- name: Code Coverage Summary Report For Merge Request
if: github.event_name == 'pull_request'
uses: 5monkeys/cobertura-action@master
with:
path: ./Interpreter.Tests/coverage.cobertura.xml
repo_token: ${{ secrets.GITHUB_TOKEN }}
minimum_coverage: 20
minimum_coverage: 80
fail_below_threshold: true
show_class_names: true
show_missing: true
Expand All @@ -53,5 +53,5 @@ jobs:
format: markdown
hide_branch_rate: true
hide_complexity: true
thresholds: '20 30'
thresholds: '80 100'

2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 5.0.x
dotnet-version: 6.0.x
- name: Publish
run: |
mkdir output
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System;
using System.Collections.Generic;
using Interpreter.Lib.VM;
using Interpreter.Lib.VM.Values;
using System.Diagnostics.CodeAnalysis;
using Interpreter.Lib.BackEnd.Values;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

namespace Interpreter.Lib.IR.Instructions
namespace Interpreter.Lib.BackEnd.Instructions
{
public class AsString : Simple
{
Expand Down Expand Up @@ -35,5 +36,22 @@ public override int Execute(VirtualMachine vm)
}

protected override string ToStringRepresentation() => $"{Left} = {right.right} as string";

[ExcludeFromCodeCoverage]
private class DoubleValueConverter : JsonConverter<double>
{
public override bool CanRead => false;

public override void WriteJson(JsonWriter writer, double value, JsonSerializer serializer) =>
// ReSharper disable once CompareOfFloatsByEqualityOperator
writer.WriteRawValue(value == Math.Truncate(value)
? JsonConvert.ToString(Convert.ToInt64(value))
: JsonConvert.ToString(value));

public override double ReadJson(JsonReader reader, Type objectType,
double existingValue, bool hasExistingValue,
JsonSerializer serializer) =>
throw new NotImplementedException("CanRead is false, so reading is unnecessary");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Interpreter.Lib.VM;

namespace Interpreter.Lib.IR.Instructions
namespace Interpreter.Lib.BackEnd.Instructions
{
public class BeginFunction : Instruction
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System;
using System.Collections.Generic;
using Interpreter.Lib.VM;

namespace Interpreter.Lib.IR.Instructions
namespace Interpreter.Lib.BackEnd.Instructions
{
public class CallFunction : Simple
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Linq;
using Interpreter.Lib.VM;

namespace Interpreter.Lib.IR.Instructions
namespace Interpreter.Lib.BackEnd.Instructions
{
public class CreateArray : Instruction
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections.Generic;
using Interpreter.Lib.VM;

namespace Interpreter.Lib.IR.Instructions
namespace Interpreter.Lib.BackEnd.Instructions
{
public class CreateObject : Instruction
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System.Collections.Generic;
using Interpreter.Lib.VM;
using Interpreter.Lib.VM.Values;
using Interpreter.Lib.BackEnd.Values;

namespace Interpreter.Lib.IR.Instructions
namespace Interpreter.Lib.BackEnd.Instructions
{
public class DotAssignment : Simple
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Interpreter.Lib.VM;

namespace Interpreter.Lib.IR.Instructions
namespace Interpreter.Lib.BackEnd.Instructions
{
public class Goto : Instruction
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Interpreter.Lib.VM;

namespace Interpreter.Lib.IR.Instructions
namespace Interpreter.Lib.BackEnd.Instructions
{
public class Halt : Instruction
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System;
using Interpreter.Lib.VM;
using Interpreter.Lib.VM.Values;
using Interpreter.Lib.BackEnd.Values;

namespace Interpreter.Lib.IR.Instructions
namespace Interpreter.Lib.BackEnd.Instructions
{
public class IfNotGoto : Goto
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System;
using System.Collections.Generic;
using Interpreter.Lib.VM;
using Interpreter.Lib.VM.Values;
using Interpreter.Lib.BackEnd.Values;

namespace Interpreter.Lib.IR.Instructions
namespace Interpreter.Lib.BackEnd.Instructions
{
public class IndexAssignment : Simple
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,22 @@
using System;
using Interpreter.Lib.VM;

namespace Interpreter.Lib.IR.Instructions
namespace Interpreter.Lib.BackEnd.Instructions
{
public abstract class Instruction : IComparable<Instruction>, IEquatable<Instruction>
public abstract class Instruction : IComparable<Instruction>
{
public int Number { get; }

public bool Leader { get; set; }

protected Instruction(int number)
{
protected Instruction(int number) =>
Number = number;
}

public virtual int Jump() => Number + 1;

public bool Branch() => Jump() != Number + 1;

public virtual bool End() => false;

public abstract int Execute(VirtualMachine vm);

public int CompareTo(Instruction other) => Number.CompareTo(other.Number);

public bool Equals(Instruction other) => other != null && Number.Equals(other.Number);

public override bool Equals(object obj) => Equals(obj as Instruction);

public override int GetHashCode() => Number;

protected abstract string ToStringRepresentation();

public override string ToString() => $"{Number}: {ToStringRepresentation()}";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using Interpreter.Lib.VM;
using Interpreter.Lib.VM.Values;
using Interpreter.Lib.BackEnd.Values;

namespace Interpreter.Lib.IR.Instructions
namespace Interpreter.Lib.BackEnd.Instructions
{
public class Print : Instruction
{
Expand All @@ -15,7 +13,7 @@ public Print(int number, IValue value) : base(number)

public override int Execute(VirtualMachine vm)
{
Console.WriteLine(_value.Get(vm.Frames.Peek()));
vm.Writer.WriteLine(_value.Get(vm.Frames.Peek()));
return Number + 1;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Interpreter.Lib.VM;
using Interpreter.Lib.VM.Values;
using Interpreter.Lib.BackEnd.Values;

namespace Interpreter.Lib.IR.Instructions
namespace Interpreter.Lib.BackEnd.Instructions
{
public class PushParameter : Instruction
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System;
using System.Collections.Generic;
using Interpreter.Lib.VM;
using Interpreter.Lib.VM.Values;
using Interpreter.Lib.BackEnd.Values;

namespace Interpreter.Lib.IR.Instructions
namespace Interpreter.Lib.BackEnd.Instructions
{
public class RemoveFromArray : Instruction
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System.Collections;
using System.Collections.Generic;
using Interpreter.Lib.VM;
using Interpreter.Lib.VM.Values;
using Interpreter.Lib.BackEnd.Values;

namespace Interpreter.Lib.IR.Instructions
namespace Interpreter.Lib.BackEnd.Instructions
{
public class Return : Instruction, IEnumerable<int>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Interpreter.Lib.VM;
using Interpreter.Lib.VM.Values;
using Interpreter.Lib.BackEnd.Values;

namespace Interpreter.Lib.IR.Instructions
namespace Interpreter.Lib.BackEnd.Instructions
{
public class Simple : Instruction
{
public string Left { get; set; }

protected (IValue left, IValue right) right;
protected string @operator;
protected readonly string @operator;

public Simple(
string left,
Expand Down Expand Up @@ -87,32 +86,6 @@ public override int Execute(VirtualMachine vm)
return Jump();
}

public void ReduceToAssignment()
{
right = ToStringRepresentation().Split('=')[1].Trim() switch
{
var s
when s.EndsWith("+ 0") || s.EndsWith("- 0") ||
s.EndsWith("* 1") || s.EndsWith("/ 1") => (null, right.left),
var s
when s.StartsWith("0 +") || s.StartsWith("1 *") => (null, right.right),
_ => throw new NotImplementedException()
};
@operator = "";
}

public void ReduceToZero()
{
right = ToStringRepresentation().Split('=')[1].Trim() switch
{
"-0" => (null, new Constant(0, "0")),
var s
when s.EndsWith("* 0") || s.StartsWith("0 *") => (null, new Constant(0, "0")),
_ => throw new NotImplementedException()
};
@operator = "";
}

protected override string ToStringRepresentation() =>
right.left == null
? $"{Left} = {@operator}{right.right}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Interpreter.Lib.VM.Values
namespace Interpreter.Lib.BackEnd.Values
{
public class Constant : IValue
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace Interpreter.Lib.VM.Values
namespace Interpreter.Lib.BackEnd.Values
{
public interface IValue : IEquatable<IValue>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Interpreter.Lib.VM.Values
namespace Interpreter.Lib.BackEnd.Values
{
public class Name : IValue
{
Expand Down
Loading