diff --git a/Fuse/AbstractRegisterState.cs b/Fuse/AbstractRegisterState.cs index 6d79e46..d6868b8 100644 --- a/Fuse/AbstractRegisterState.cs +++ b/Fuse/AbstractRegisterState.cs @@ -3,22 +3,22 @@ // namespace Fuse { + using EightBit; using System; using System.Collections.Generic; using System.Collections.ObjectModel; - using EightBit; public abstract class AbstractRegisterState { - private readonly List registers = new List(); - public ReadOnlyCollection Registers => this.MutableRegisters.AsReadOnly(); public bool Halted { get; protected set; } = false; public int TStates { get; protected set; } = -1; - protected List MutableRegisters => this.registers; + protected List MutableRegisters { get; } = []; + + private static readonly char[] separator = [' ', '\t']; public void Parse(Lines lines) { @@ -30,7 +30,7 @@ namespace Fuse protected virtual void ParseInternalState(string line) { - var tokens = line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); + var tokens = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); this.ParseInternalState(tokens); } @@ -39,9 +39,9 @@ namespace Fuse protected virtual void ParseExternalState(Lines lines) { var line = lines.ReadLine(); - foreach (var token in line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)) + foreach (var token in line.Split(separator, StringSplitOptions.RemoveEmptyEntries)) { - this.registers.Add(new Register16(Convert.ToUInt16(token, 16))); + this.MutableRegisters.Add(new Register16(Convert.ToUInt16(token, 16))); } } } diff --git a/Fuse/IRegisterState.cs b/Fuse/IRegisterState.cs index 55177f4..359df31 100644 --- a/Fuse/IRegisterState.cs +++ b/Fuse/IRegisterState.cs @@ -3,8 +3,8 @@ // namespace Fuse { - using System.Collections.ObjectModel; using EightBit; + using System.Collections.ObjectModel; public interface IRegisterState { diff --git a/Fuse/Lines.cs b/Fuse/Lines.cs index 658c8e0..29847c7 100644 --- a/Fuse/Lines.cs +++ b/Fuse/Lines.cs @@ -8,14 +8,12 @@ namespace Fuse using System.Diagnostics; using System.IO; - public class Lines + public class Lines(string path) { - private readonly string path; - private readonly List lines = new List(); + private readonly string path = path; + private readonly List lines = []; private int position = -1; - public Lines(string path) => this.path = path; - public bool EndOfFile => this.position == this.lines.Count; public void Read() diff --git a/Fuse/MemoryDatum.cs b/Fuse/MemoryDatum.cs index a834df9..f066351 100644 --- a/Fuse/MemoryDatum.cs +++ b/Fuse/MemoryDatum.cs @@ -9,16 +9,18 @@ namespace Fuse public class MemoryDatum { - private readonly List bytes = new List(); + private readonly List bytes = []; public ushort Address { get; private set; } = (ushort)EightBit.Mask.Sixteen; public ReadOnlyCollection Bytes => this.bytes.AsReadOnly(); + private static readonly char[] separator = [' ', '\t']; + public void Parse(string line) { ArgumentNullException.ThrowIfNullOrWhiteSpace(line); - var tokens = line.Split(new char[] { ' ', '\t' }); + var tokens = line.Split(separator); this.Parse(tokens); } diff --git a/Fuse/Result.cs b/Fuse/Result.cs index 1afa761..ee57c1a 100644 --- a/Fuse/Result.cs +++ b/Fuse/Result.cs @@ -10,14 +10,13 @@ namespace Fuse public class Result where T : Fuse.IRegisterState, new() { - private readonly TestEvents events = new TestEvents(); - private readonly List memoryData = new List(); + private readonly List memoryData = []; - public string Description { get; private set; } + public string? Description { get; private set; } public T RegisterState { get; } = new T(); - public TestEvents Events => this.events; + public TestEvents Events { get; } = new(); public ReadOnlyCollection MemoryData => this.memoryData.AsReadOnly(); @@ -35,7 +34,7 @@ namespace Fuse return false; } - this.events.Parse(lines); + this.Events.Parse(lines); this.RegisterState.Parse(lines); bool finished; diff --git a/Fuse/Results.cs b/Fuse/Results.cs index e5b17bb..6b0ea24 100644 --- a/Fuse/Results.cs +++ b/Fuse/Results.cs @@ -4,15 +4,14 @@ namespace Fuse { using System.Collections.Generic; + using System.Diagnostics; - public class Results + public class Results(string path) where T : Fuse.IRegisterState, new() { - private readonly Lines lines; + private readonly Lines lines = new(path); - public Results(string path) => this.lines = new Lines(path); - - public Dictionary> Container { get; } = new Dictionary>(); + public Dictionary> Container { get; } = []; public void Read() => this.lines.Read(); @@ -23,6 +22,7 @@ namespace Fuse var result = new Result(); if (result.TryParse(this.lines)) { + Debug.Assert(result.Description is not null); this.Container.Add(result.Description, result); } } diff --git a/Fuse/Test.cs b/Fuse/Test.cs index e33e6a1..ac9ff63 100644 --- a/Fuse/Test.cs +++ b/Fuse/Test.cs @@ -9,9 +9,9 @@ namespace Fuse public class Test where T : Fuse.IRegisterState, new() { - private readonly List memoryData = new List(); + private readonly List memoryData = []; - public string Description { get; private set; } + public string? Description { get; private set; } public T RegisterState { get; } = new T(); diff --git a/Fuse/TestEvent.cs b/Fuse/TestEvent.cs index 80c943e..f16f01f 100644 --- a/Fuse/TestEvent.cs +++ b/Fuse/TestEvent.cs @@ -3,8 +3,8 @@ // namespace Fuse { - using System; using EightBit; + using System; public class TestEvent { @@ -27,7 +27,7 @@ namespace Fuse public int Cycles => this.cycles; - public string Specifier { get; private set; } + public string? Specifier { get; private set; } public ushort Address { get; private set; } = (ushort)EightBit.Mask.Sixteen; @@ -35,6 +35,8 @@ namespace Fuse private bool ContentionEvent { get; set; } = false; + private static readonly char[] separator = [' ', '\t']; + public bool TryParse(Lines lines) { ArgumentNullException.ThrowIfNull(lines); @@ -61,7 +63,7 @@ namespace Fuse private bool TryParseLine(string line) { - var split = line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); + var split = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); return this.TryParseLine(split); } diff --git a/Fuse/TestEvents.cs b/Fuse/TestEvents.cs index 18273a5..a32a889 100644 --- a/Fuse/TestEvents.cs +++ b/Fuse/TestEvents.cs @@ -8,7 +8,7 @@ namespace Fuse public class TestEvents { - private readonly List container = new List(); + private readonly List container = []; public ReadOnlyCollection Container => this.container.AsReadOnly(); diff --git a/Fuse/Tests.cs b/Fuse/Tests.cs index f3ab905..99a6bdf 100644 --- a/Fuse/Tests.cs +++ b/Fuse/Tests.cs @@ -4,15 +4,14 @@ namespace Fuse { using System.Collections.Generic; + using System.Diagnostics; - public class Tests + public class Tests(string path) where T : Fuse.IRegisterState, new() { - private readonly Lines lines; + private readonly Lines lines = new(path); - public Tests(string path) => this.lines = new Lines(path); - - public Dictionary> Container { get; } = new Dictionary>(); + public Dictionary> Container { get; } = []; public void Read() => this.lines.Read(); @@ -23,6 +22,7 @@ namespace Fuse var test = new Test(); if (test.TryParse(this.lines)) { + Debug.Assert(test.Description is not null); this.Container.Add(test.Description, test); } }