Skip to content

Commit fde29b3

Browse files
authored
Использование последних наворотов шарпа (#26)
* versioning * enabling implicit usings (#25) * local scoped namespaces (#27)
1 parent 6cfd18f commit fde29b3

File tree

150 files changed

+4398
-4697
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+4398
-4697
lines changed
Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,53 @@
1-
using System;
21
using System.Diagnostics.CodeAnalysis;
32
using System.Text.Json;
43
using System.Text.Json.Serialization;
54
using Interpreter.Lib.BackEnd.Values;
5+
using SystemType = System.Type;
66

7-
namespace Interpreter.Lib.BackEnd.Instructions
7+
namespace Interpreter.Lib.BackEnd.Instructions;
8+
9+
public class AsString : Simple
810
{
9-
public class AsString : Simple
11+
public AsString(string left, IValue right, int number) :
12+
base(left, (null, right), "", number)
1013
{
11-
public AsString(string left, IValue right, int number) :
12-
base(left, (null, right), "", number)
13-
{
14-
}
14+
}
1515

16-
public override int Execute(VirtualMachine vm)
17-
{
18-
var frame = vm.Frames.Peek();
19-
frame[Left] = JsonSerializer.Serialize(
20-
right.right.Get(frame),
21-
new JsonSerializerOptions
22-
{
23-
WriteIndented = true,
24-
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
25-
ReferenceHandler = ReferenceHandler.IgnoreCycles,
26-
Converters = { new DoubleValueWriteConverter() },
27-
NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals
28-
}
29-
);
16+
public override int Execute(VirtualMachine vm)
17+
{
18+
var frame = vm.Frames.Peek();
19+
frame[Left] = JsonSerializer.Serialize(
20+
right.right.Get(frame),
21+
new JsonSerializerOptions
22+
{
23+
WriteIndented = true,
24+
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
25+
ReferenceHandler = ReferenceHandler.IgnoreCycles,
26+
Converters = { new DoubleValueWriteConverter() },
27+
NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals
28+
}
29+
);
3030

31-
return Jump();
32-
}
31+
return Jump();
32+
}
3333

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

36-
[ExcludeFromCodeCoverage]
37-
private class DoubleValueWriteConverter : JsonConverter<double>
38-
{
39-
public override double Read(ref Utf8JsonReader reader,
40-
Type typeToConvert, JsonSerializerOptions options) =>
41-
throw new NotImplementedException();
36+
[ExcludeFromCodeCoverage]
37+
private class DoubleValueWriteConverter : JsonConverter<double>
38+
{
39+
public override double Read(ref Utf8JsonReader reader,
40+
SystemType typeToConvert, JsonSerializerOptions options) =>
41+
throw new NotImplementedException();
4242

43-
public override void Write(Utf8JsonWriter writer,
44-
double value, JsonSerializerOptions options)
45-
{
46-
// ReSharper disable once CompareOfFloatsByEqualityOperator
47-
if (value == Math.Truncate(value))
48-
writer.WriteNumberValue(Convert.ToInt64(value));
49-
else
50-
writer.WriteNumberValue(value);
51-
}
43+
public override void Write(Utf8JsonWriter writer,
44+
double value, JsonSerializerOptions options)
45+
{
46+
// ReSharper disable once CompareOfFloatsByEqualityOperator
47+
if (value == Math.Truncate(value))
48+
writer.WriteNumberValue(Convert.ToInt64(value));
49+
else
50+
writer.WriteNumberValue(value);
5251
}
5352
}
5453
}
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
namespace Interpreter.Lib.BackEnd.Instructions
1+
namespace Interpreter.Lib.BackEnd.Instructions;
2+
3+
public class BeginFunction : Instruction
24
{
3-
public class BeginFunction : Instruction
4-
{
5-
private readonly FunctionInfo _function;
5+
private readonly FunctionInfo _function;
66

7-
public BeginFunction(int number, FunctionInfo function) : base(number)
8-
{
9-
_function = function;
10-
}
7+
public BeginFunction(int number, FunctionInfo function) : base(number)
8+
{
9+
_function = function;
10+
}
1111

12-
public override int Execute(VirtualMachine vm) => Number + 1;
12+
public override int Execute(VirtualMachine vm) => Number + 1;
1313

14-
protected override string ToStringRepresentation() => $"BeginFunction {_function.CallId()}";
15-
}
14+
protected override string ToStringRepresentation() => $"BeginFunction {_function.CallId()}";
1615
}
Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,47 @@
1-
using System;
2-
using System.Collections.Generic;
1+
namespace Interpreter.Lib.BackEnd.Instructions;
32

4-
namespace Interpreter.Lib.BackEnd.Instructions
3+
public class CallFunction : Simple
54
{
6-
public class CallFunction : Simple
7-
{
8-
private readonly FunctionInfo _function;
9-
private readonly int _numberOfArguments;
5+
private readonly FunctionInfo _function;
6+
private readonly int _numberOfArguments;
107

11-
public CallFunction(FunctionInfo function, int number, int numberOfArguments, string left = null) :
12-
base(left, (null, null), "Call ", number)
13-
{
14-
_function = function;
15-
_numberOfArguments = numberOfArguments + Convert.ToInt32(function.MethodOf != null);
16-
}
8+
public CallFunction(FunctionInfo function, int number, int numberOfArguments, string left = null) :
9+
base(left, (null, null), "Call ", number)
10+
{
11+
_function = function;
12+
_numberOfArguments = numberOfArguments + Convert.ToInt32(function.MethodOf != null);
13+
}
1714

18-
public override int Jump() => _function.Location;
15+
public override int Jump() => _function.Location;
1916

20-
public override int Execute(VirtualMachine vm)
21-
{
22-
var frame = new Frame(Number + 1, vm.Frames.Peek());
17+
public override int Execute(VirtualMachine vm)
18+
{
19+
var frame = new Frame(Number + 1, vm.Frames.Peek());
2320

24-
var i = 0;
25-
var args = new List<(string Id, object Value)>();
26-
while (i < _numberOfArguments)
27-
{
28-
args.Add(vm.Arguments.Pop());
29-
frame[args[i].Id] = args[i].Value;
30-
i++;
31-
}
21+
var i = 0;
22+
var args = new List<(string Id, object Value)>();
23+
while (i < _numberOfArguments)
24+
{
25+
args.Add(vm.Arguments.Pop());
26+
frame[args[i].Id] = args[i].Value;
27+
i++;
28+
}
3229

33-
if (_function.MethodOf != null)
30+
if (_function.MethodOf != null)
31+
{
32+
var obj = (Dictionary<string, object>) frame[_function.MethodOf];
33+
foreach (var (key, value) in obj)
3434
{
35-
var obj = (Dictionary<string, object>) frame[_function.MethodOf];
36-
foreach (var (key, value) in obj)
37-
{
38-
frame[key] = value;
39-
}
35+
frame[key] = value;
4036
}
41-
42-
vm.CallStack.Push(new Call(Number, _function, args, Left));
43-
vm.Frames.Push(frame);
44-
return _function.Location;
4537
}
4638

47-
protected override string ToStringRepresentation() => Left == null
48-
? $"Call {_function}, {_numberOfArguments}"
49-
: $"{Left} = Call {_function}, {_numberOfArguments}";
39+
vm.CallStack.Push(new Call(Number, _function, args, Left));
40+
vm.Frames.Push(frame);
41+
return _function.Location;
5042
}
43+
44+
protected override string ToStringRepresentation() => Left == null
45+
? $"Call {_function}, {_numberOfArguments}"
46+
: $"{Left} = Call {_function}, {_numberOfArguments}";
5147
}
Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
1-
using System.Linq;
1+
namespace Interpreter.Lib.BackEnd.Instructions;
22

3-
namespace Interpreter.Lib.BackEnd.Instructions
3+
public class CreateArray : Instruction
44
{
5-
public class CreateArray : Instruction
6-
{
7-
private readonly string _id;
8-
private readonly int _size;
5+
private readonly string _id;
6+
private readonly int _size;
97

10-
public CreateArray(int number, string id, int size) : base(number)
11-
{
12-
_id = id;
13-
_size = size;
14-
}
15-
16-
public override int Execute(VirtualMachine vm)
17-
{
18-
var frame = vm.Frames.Peek();
19-
frame[_id] = new object[_size].ToList();
20-
return Number + 1;
21-
}
8+
public CreateArray(int number, string id, int size) : base(number)
9+
{
10+
_id = id;
11+
_size = size;
12+
}
2213

23-
protected override string ToStringRepresentation() => $"array {_id} = [{_size}]";
14+
public override int Execute(VirtualMachine vm)
15+
{
16+
var frame = vm.Frames.Peek();
17+
frame[_id] = new object[_size].ToList();
18+
return Number + 1;
2419
}
20+
21+
protected override string ToStringRepresentation() => $"array {_id} = [{_size}]";
2522
}
Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
1-
using System.Collections.Generic;
1+
namespace Interpreter.Lib.BackEnd.Instructions;
22

3-
namespace Interpreter.Lib.BackEnd.Instructions
3+
public class CreateObject : Instruction
44
{
5-
public class CreateObject : Instruction
6-
{
7-
private readonly string _id;
5+
private readonly string _id;
86

9-
public CreateObject(int number, string id) : base(number)
10-
{
11-
_id = id;
12-
}
13-
14-
public override int Execute(VirtualMachine vm)
15-
{
16-
var frame = vm.Frames.Peek();
17-
frame[_id] = new Dictionary<string, object>();
18-
return Number + 1;
19-
}
7+
public CreateObject(int number, string id) : base(number)
8+
{
9+
_id = id;
10+
}
2011

21-
protected override string ToStringRepresentation() => $"object {_id} = {{}}";
12+
public override int Execute(VirtualMachine vm)
13+
{
14+
var frame = vm.Frames.Peek();
15+
frame[_id] = new Dictionary<string, object>();
16+
return Number + 1;
2217
}
18+
19+
protected override string ToStringRepresentation() => $"object {_id} = {{}}";
2320
}
Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1-
using System.Collections.Generic;
21
using Interpreter.Lib.BackEnd.Values;
32

4-
namespace Interpreter.Lib.BackEnd.Instructions
3+
namespace Interpreter.Lib.BackEnd.Instructions;
4+
5+
public class DotAssignment : Simple
56
{
6-
public class DotAssignment : Simple
7+
public DotAssignment(string left, (IValue left, IValue right) right, int number) :
8+
base(left, right, ".", number)
79
{
8-
public DotAssignment(string left, (IValue left, IValue right) right, int number) :
9-
base(left, right, ".", number)
10-
{
11-
}
12-
13-
public override int Execute(VirtualMachine vm)
14-
{
15-
var frame = vm.Frames.Peek();
16-
var obj = (Dictionary<string, object>) frame[Left];
17-
var field = (string) right.left.Get(frame) ?? string.Empty;
18-
obj[field] = right.right.Get(frame);
19-
return Number + 1;
20-
}
10+
}
2111

22-
protected override string ToStringRepresentation() =>
23-
$"{Left}{@operator}{right.left} = {right.right}";
12+
public override int Execute(VirtualMachine vm)
13+
{
14+
var frame = vm.Frames.Peek();
15+
var obj = (Dictionary<string, object>) frame[Left];
16+
var field = (string) right.left.Get(frame) ?? string.Empty;
17+
obj[field] = right.right.Get(frame);
18+
return Number + 1;
2419
}
20+
21+
protected override string ToStringRepresentation() =>
22+
$"{Left}{@operator}{right.left} = {right.right}";
2523
}
Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
namespace Interpreter.Lib.BackEnd.Instructions
1+
namespace Interpreter.Lib.BackEnd.Instructions;
2+
3+
public class Goto : Instruction
24
{
3-
public class Goto : Instruction
4-
{
5-
protected int jump;
5+
protected int jump;
66

7-
public Goto(int jump, int number) : base(number)
8-
{
9-
this.jump = jump;
10-
}
7+
public Goto(int jump, int number) : base(number)
8+
{
9+
this.jump = jump;
10+
}
1111

12-
public override int Jump() => jump;
12+
public override int Jump() => jump;
1313

14-
public override int Execute(VirtualMachine vm) => Jump();
14+
public override int Execute(VirtualMachine vm) => Jump();
1515

16-
public void SetJump(int newJump) => jump = newJump;
16+
public void SetJump(int newJump) => jump = newJump;
1717

18-
protected override string ToStringRepresentation() => $"Goto {Jump()}";
19-
}
18+
protected override string ToStringRepresentation() => $"Goto {Jump()}";
2019
}

0 commit comments

Comments
 (0)