Skip to content

Commit 70a5a42

Browse files
committed
nrt refac iaddress
1 parent 1e3399e commit 70a5a42

File tree

31 files changed

+55
-92
lines changed

31 files changed

+55
-92
lines changed

src/Application/HydraScript.Application.CodeGeneration/Visitors/InstructionProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public AddressedInstructions Visit(WhileStatement visitable)
168168
}
169169

170170
result.AddRange(visitable.Statement.Accept(This));
171-
for (var address = result.Start; address != null; address = address?.Next)
171+
for (var address = result.Start; address != null; address = address.Next)
172172
{
173173
if (result[address] is Goto { JumpType: not null } g)
174174
{
@@ -222,7 +222,7 @@ public AddressedInstructions Visit(IfStatement visitable)
222222
if (visitable.HasElseBlock())
223223
result.AddRange(visitable.Else?.Accept(This) ?? []);
224224

225-
for (var address = result.Start; address != null; address = address?.Next)
225+
for (var address = result.Start; address != null; address = address.Next)
226226
{
227227
if (result[address] is Goto { JumpType: InsideStatementJumpType.Break } g)
228228
g.SetJump(endBlockLabel);

src/Domain/HydraScript.Domain.BackEnd/AddressedInstructions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private void AddWithAddress(IExecutableInstruction instruction, IAddress newAddr
5454

5555
public void AddRange(AddressedInstructions instructions)
5656
{
57-
for (var address = instructions.Start; address != null; address = address?.Next)
57+
for (var address = instructions.Start; address != null; address = address.Next)
5858
{
5959
AddWithAddress(instructions[address], address);
6060
}

src/Domain/HydraScript.Domain.BackEnd/IAddress.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace HydraScript.Domain.BackEnd;
22

33
public interface IAddress : IEquatable<IAddress>
44
{
5-
public IAddress Next { get; set; }
5+
public IAddress? Next { get; set; }
66

77
public string Name { get; }
88
}

src/Domain/HydraScript.Domain.BackEnd/IExecutableInstruction.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ namespace HydraScript.Domain.BackEnd;
33
public interface IExecutableInstruction
44
{
55
public IAddress Address { get; set; }
6-
public IAddress Execute(IExecuteParams executeParams);
7-
public bool End { get; }
6+
public IAddress? Execute(IExecuteParams executeParams);
87
}

src/Domain/HydraScript.Domain.BackEnd/Impl/Addresses/HashAddress.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class HashAddress(int seed) : IAddress
99

1010
private readonly Guid _id = Guid.NewGuid();
1111

12-
public IAddress Next { get; set; } = default!;
12+
public IAddress? Next { get; set; }
1313

1414
public string Name
1515
{

src/Domain/HydraScript.Domain.BackEnd/Impl/Addresses/Label.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public class Label(string name) : IAddress
44
{
55
public string Name { get; } = name;
66

7-
public IAddress Next { get; set; } = default!;
7+
public IAddress? Next { get; set; }
88

99
public bool Equals(IAddress? other) =>
1010
other is Label label &&
Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
11
namespace HydraScript.Domain.BackEnd.Impl.Instructions;
22

3-
public abstract class BlockLabel : Instruction
3+
public abstract class BlockLabel(
4+
BlockLabel.BlockPosition blockPosition,
5+
BlockType blockType,
6+
string blockId) : Instruction
47
{
5-
private readonly BlockPosition _blockPosition;
6-
private readonly BlockType _blockType;
7-
private readonly string _blockId;
8-
9-
protected BlockLabel(BlockPosition blockPosition, BlockType blockType, string blockId)
10-
{
11-
_blockPosition = blockPosition;
12-
_blockType = blockType;
13-
_blockId = blockId;
14-
}
15-
16-
public override IAddress Execute(IExecuteParams executeParams) =>
17-
Address.Next;
8+
public override IAddress? Execute(IExecuteParams executeParams) => Address.Next;
189

1910
protected override string ToStringInternal() =>
20-
$"{_blockPosition}{_blockType} {_blockId}";
11+
$"{blockPosition}{blockType} {blockId}";
2112

2213
protected enum BlockPosition
2314
{
@@ -33,14 +24,8 @@ public enum BlockType
3324
Condition
3425
}
3526

36-
public class BeginBlock : BlockLabel
37-
{
38-
public BeginBlock(BlockType blockType, string blockId) :
39-
base(BlockPosition.Begin, blockType, blockId) { }
40-
}
27+
public class BeginBlock(BlockType blockType, string blockId) :
28+
BlockLabel(BlockPosition.Begin, blockType, blockId);
4129

42-
public class EndBlock : BlockLabel
43-
{
44-
public EndBlock(BlockType blockType, string blockId) :
45-
base(BlockPosition.End, blockType, blockId) { }
46-
}
30+
public class EndBlock(BlockType blockType, string blockId) :
31+
BlockLabel(BlockPosition.End, blockType, blockId);

src/Domain/HydraScript.Domain.BackEnd/Impl/Instructions/Halt.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
using HydraScript.Domain.BackEnd.Impl.Addresses;
2-
31
namespace HydraScript.Domain.BackEnd.Impl.Instructions;
42

53
public class Halt : Instruction
64
{
7-
public override bool End => true;
8-
9-
public override IAddress Execute(IExecuteParams executeParams)
5+
public override IAddress? Execute(IExecuteParams executeParams)
106
{
117
executeParams.Frames.Pop();
12-
return new HashAddress(seed: 0);
8+
return null;
139
}
1410

1511
protected override string ToStringInternal() => "End";

src/Domain/HydraScript.Domain.BackEnd/Impl/Instructions/Instruction.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace HydraScript.Domain.BackEnd.Impl.Instructions;
22

33
public abstract class Instruction : IExecutableInstruction
44
{
5-
private IAddress _address = default!;
5+
private IAddress _address = null!;
66

77
public IAddress Address
88
{
@@ -16,9 +16,7 @@ public IAddress Address
1616

1717
protected virtual void OnSetOfAddress(IAddress address) { }
1818

19-
public abstract IAddress Execute(IExecuteParams executeParams);
20-
21-
public virtual bool End => false;
19+
public abstract IAddress? Execute(IExecuteParams executeParams);
2220

2321
protected abstract string ToStringInternal();
2422

src/Domain/HydraScript.Domain.BackEnd/Impl/Instructions/PopParameter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace HydraScript.Domain.BackEnd.Impl.Instructions;
22

33
public class PopParameter(string parameter, object? defaultValue = null) : Instruction
44
{
5-
public override IAddress Execute(IExecuteParams executeParams)
5+
public override IAddress? Execute(IExecuteParams executeParams)
66
{
77
var frame = executeParams.Frames.Peek();
88
if (executeParams.Arguments.TryDequeue(out var argument))

0 commit comments

Comments
 (0)