From 5b3b25bef90d4be4489e7959df6bf67e91f6826a Mon Sep 17 00:00:00 2001 From: Rutger van Bergen Date: Fri, 23 Aug 2024 12:43:51 +0200 Subject: [PATCH 1/3] Bump Lib and Assember to .NET 8, apply heaps of C# 12 improvements --- src/MixAssembler/Assembler.cs | 8 +-- src/MixAssembler/AssemblingStatus.cs | 2 +- src/MixAssembler/Finding/AssemblyError.cs | 9 ++- src/MixAssembler/Finding/AssemblyFinding.cs | 25 +++---- src/MixAssembler/Finding/AssemblyInfo.cs | 11 +-- src/MixAssembler/Finding/AssemblyWarning.cs | 9 ++- src/MixAssembler/Finding/ValidationFinding.cs | 13 ++-- .../LoaderInstructionParameters.cs | 37 ++++------ .../Instruction/MixInstructionParameters.cs | 63 +++++++----------- .../Instruction/ParsedSourceLine.cs | 41 ++++-------- .../Instruction/PreInstruction.cs | 16 ++--- src/MixAssembler/MixAssembler.csproj | 2 +- src/MixAssembler/Parser.cs | 20 +++--- src/MixAssembler/ParsingStatus.cs | 9 +-- .../Symbol/LiteralConstantSymbol.cs | 19 ++---- src/MixAssembler/Symbol/LocalSymbol.cs | 18 ++--- src/MixAssembler/Symbol/ValueSymbol.cs | 12 +--- src/MixAssembler/Value/ExpressionValue.cs | 24 +++---- src/MixAssembler/Value/WValue.cs | 6 +- .../Components/AssemblyFindingListView.cs | 2 +- src/MixEmul/Components/DeviceStatusControl.cs | 2 +- src/MixEmul/Components/DevicesControl.cs | 22 ++---- src/MixEmul/Components/EditorList.cs | 13 ++-- src/MixEmul/Components/FieldKeyEventArgs.cs | 9 +-- src/MixEmul/Components/IndexKeyEventArgs.cs | 9 +-- .../Components/LinkedItemsSelectorControl.cs | 28 +++----- src/MixEmul/Components/LogListView.cs | 2 +- src/MixEmul/Components/MemoryEditor.cs | 27 ++++---- src/MixEmul/Components/MemoryWordEditor.cs | 3 +- .../Components/MixByteCollectionEditorList.cs | 7 +- src/MixEmul/Components/PreferencesForm.cs | 6 +- .../Components/SourceAndFindingsForm.cs | 3 +- src/MixEmul/Components/SymbolListView.cs | 2 +- src/MixEmul/Components/TeletypeForm.cs | 3 +- .../Components/TextFileDeviceEditor.cs | 9 +-- src/MixEmul/Components/WordEditorList.cs | Bin 674 -> 344 bytes .../Events/AddressSelectedEventArgs.cs | 9 +-- src/MixEmul/Events/DeviceEventArgs.cs | 9 +-- ...teCollectionValueEditorChangedEventArgs.cs | 16 ++--- .../Events/WordValueEditorChangedEventArgs.cs | 16 ++--- src/MixEmul/MixEmul.csproj | 2 +- src/MixEmul/MixForm.cs | 38 +++++------ src/MixEmul/MixForm.handlers.cs | 22 +++--- src/MixEmul/Settings/Configuration.cs | 14 ++-- src/MixEmul/Settings/GuiSettings.cs | 14 ++-- src/MixEmul/Utils/CardDeckExporter.cs | 8 +-- src/MixLib/Device/CardReaderDevice.cs | 4 +- src/MixLib/Device/CardWriterDevice.cs | 4 +- src/MixLib/Device/DiskDevice.cs | 10 +-- src/MixLib/Device/InOutputOperands.cs | 24 +++---- src/MixLib/Device/MixDevice.cs | 37 +++------- src/MixLib/Device/PaperTapeDevice.cs | 19 ++---- src/MixLib/Device/PrinterDevice.cs | 8 +-- src/MixLib/Device/Settings/DeviceSettings.cs | 4 +- src/MixLib/Device/Step/BinaryReadStep.cs | 17 ++--- src/MixLib/Device/Step/BinaryWriteStep.cs | 16 ++--- src/MixLib/Device/Step/CloseStreamStep.cs | 4 +- src/MixLib/Device/Step/NoOpStep.cs | 13 +--- src/MixLib/Device/Step/StreamStep.cs | 7 +- src/MixLib/Device/Step/TextReadStep.cs | 16 ++--- src/MixLib/Device/Step/TextWriteStep.cs | 18 ++--- src/MixLib/Device/Step/TickingStep.cs | 21 ++---- src/MixLib/Device/TapeDevice.cs | 11 +-- src/MixLib/Device/TeletypeDevice.cs | 35 +++------- src/MixLib/Events/DeviceReportingEventArgs.cs | 9 +-- src/MixLib/Events/ReportingEventArgs.cs | 16 ++--- .../Instruction/FloatingPointInstructions.cs | 26 +++----- src/MixLib/Instruction/IOInstructions.cs | 2 +- src/MixLib/Instruction/InstructionBase.cs | 11 ++- src/MixLib/Instruction/InstructionHelpers.cs | 4 +- src/MixLib/Instruction/InstructionText.cs | 25 +++---- src/MixLib/Instruction/LoaderInstruction.cs | 25 ++----- src/MixLib/Instruction/MiscInstructions.cs | 34 ++++------ src/MixLib/Instruction/MixInstruction.cs | 6 +- .../Instruction/RuntimeValidationError.cs | 20 ++---- src/MixLib/InstructionSet.cs | 11 ++- src/MixLib/LoaderInstructions.cs | 4 +- src/MixLib/Memory.cs | 6 +- src/MixLib/Misc/LogLine.cs | 28 +++----- src/MixLib/Mix.cs | 3 +- src/MixLib/MixLib.csproj | 2 +- src/MixLib/Modules/FloatingPointModule.cs | 2 +- src/MixLib/Modules/Settings/ModuleSettings.cs | 8 +-- src/MixLib/Type/FullWord.cs | 2 +- src/MixLib/Type/IWord.cs | 2 +- src/MixLib/Type/Register.cs | 15 ++--- src/MixLib/Type/SymbolBase.cs | 7 +- src/MixLib/Type/SymbolCollection.cs | 4 +- src/MixLib/Type/VirtualMemoryFullWord.cs | 24 +++---- src/MixLib/Type/Word.cs | 15 ++++- 90 files changed, 441 insertions(+), 777 deletions(-) diff --git a/src/MixAssembler/Assembler.cs b/src/MixAssembler/Assembler.cs index c6c859d..b1dbd4d 100644 --- a/src/MixAssembler/Assembler.cs +++ b/src/MixAssembler/Assembler.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using MixAssembler.Finding; @@ -71,12 +71,10 @@ public static InstructionInstanceBase[] Assemble(string[] sourceLines, out PreIn if (status.Findings.ContainsErrors) return null; - symbols = new SymbolCollection(); - foreach (SymbolBase symbol in status.Symbols.Where(symbol => symbol is ValueSymbol)) - symbols.Add(symbol); + symbols = [.. status.Symbols.Where(symbol => symbol is ValueSymbol)]; status.Findings.Add(new AssemblyInfo("assembly completed successfully", int.MinValue, LineSection.EntireLine, 0, 0)); - return list.ToArray(); + return [.. list]; } public static InstructionInstanceBase Assemble(string instructionLine, int locationCounter, out ParsedSourceLine parsedLine, SymbolCollection symbols, out AssemblyFindingCollection findings) diff --git a/src/MixAssembler/AssemblingStatus.cs b/src/MixAssembler/AssemblingStatus.cs index 0b07ab9..8e7c2e1 100644 --- a/src/MixAssembler/AssemblingStatus.cs +++ b/src/MixAssembler/AssemblingStatus.cs @@ -5,7 +5,7 @@ namespace MixAssembler { public class AssemblingStatus { - public AssemblyFindingCollection Findings { get; } = new(); + public AssemblyFindingCollection Findings { get; } = []; public void ReportError(LineSection lineSection, int causeStartIndex, int causeLength, ValidationError error) => Findings.Add(new AssemblyError(LineNumber, lineSection, causeStartIndex, causeLength, error)); diff --git a/src/MixAssembler/Finding/AssemblyError.cs b/src/MixAssembler/Finding/AssemblyError.cs index 5e01eaa..d913378 100644 --- a/src/MixAssembler/Finding/AssemblyError.cs +++ b/src/MixAssembler/Finding/AssemblyError.cs @@ -1,10 +1,9 @@ -using MixLib.Misc; +using MixLib.Misc; namespace MixAssembler.Finding { - public class AssemblyError : ValidationFinding + public class AssemblyError(int lineNumber, LineSection lineSection, int causeStartIndex, int causeLength, ValidationError error) + : ValidationFinding(Severity.Error, lineNumber, lineSection, causeStartIndex, causeLength, error) { - public AssemblyError(int lineNumber, LineSection lineSection, int causeStartIndex, int causeLength, ValidationError error) - : base(Severity.Error, lineNumber, lineSection, causeStartIndex, causeLength, error) { } - } + } } diff --git a/src/MixAssembler/Finding/AssemblyFinding.cs b/src/MixAssembler/Finding/AssemblyFinding.cs index 3ac46e8..68d88f4 100644 --- a/src/MixAssembler/Finding/AssemblyFinding.cs +++ b/src/MixAssembler/Finding/AssemblyFinding.cs @@ -1,27 +1,18 @@ -using MixLib.Misc; +using MixLib.Misc; namespace MixAssembler.Finding { - public abstract class AssemblyFinding - { - public int Length { get; private set; } - public int LineNumber { get; private set; } - public LineSection LineSection { get; private set; } - public Severity Severity { get; private set; } - public int StartCharIndex { get; private set; } + public abstract class AssemblyFinding(Severity severity, int lineNumber, LineSection section, int startCharIndex, int length) + { + public int Length { get; private set; } = length; + public int LineNumber { get; private set; } = lineNumber; + public LineSection LineSection { get; private set; } = section; + public Severity Severity { get; private set; } = severity; + public int StartCharIndex { get; private set; } = startCharIndex; public const int NoNumber = int.MinValue; - protected AssemblyFinding(Severity severity, int lineNumber, LineSection section, int startCharIndex, int length) - { - LineSection = section; - StartCharIndex = startCharIndex; - Length = length; - Severity = severity; - LineNumber = lineNumber; - } - public abstract string Message { get; } } } diff --git a/src/MixAssembler/Finding/AssemblyInfo.cs b/src/MixAssembler/Finding/AssemblyInfo.cs index 9066e31..99f8f84 100644 --- a/src/MixAssembler/Finding/AssemblyInfo.cs +++ b/src/MixAssembler/Finding/AssemblyInfo.cs @@ -1,14 +1,9 @@ namespace MixAssembler.Finding { - public class AssemblyInfo : AssemblyFinding + public class AssemblyInfo(string message, int lineNumber, LineSection lineSection, int startCharIndex, int length) + : AssemblyFinding(MixLib.Misc.Severity.Info, lineNumber, lineSection, startCharIndex, length) { - private readonly string message; - - public AssemblyInfo(string message, int lineNumber, LineSection lineSection, int startCharIndex, int length) - : base(MixLib.Misc.Severity.Info, lineNumber, lineSection, startCharIndex, length) - => this.message = message; - public override string Message - => this.message; + => message; } } diff --git a/src/MixAssembler/Finding/AssemblyWarning.cs b/src/MixAssembler/Finding/AssemblyWarning.cs index 580cf55..bbe10e5 100644 --- a/src/MixAssembler/Finding/AssemblyWarning.cs +++ b/src/MixAssembler/Finding/AssemblyWarning.cs @@ -1,10 +1,9 @@ -using MixLib.Misc; +using MixLib.Misc; namespace MixAssembler.Finding { - public class AssemblyWarning : ValidationFinding + public class AssemblyWarning(int lineNumber, LineSection lineSection, int causeStartIndex, int causeLength, ValidationError error) + : ValidationFinding(Severity.Warning, lineNumber, lineSection, causeStartIndex, causeLength, error) { - public AssemblyWarning(int lineNumber, LineSection lineSection, int causeStartIndex, int causeLength, ValidationError error) - : base(Severity.Warning, lineNumber, lineSection, causeStartIndex, causeLength, error) { } - } + } } diff --git a/src/MixAssembler/Finding/ValidationFinding.cs b/src/MixAssembler/Finding/ValidationFinding.cs index 879f101..53d3736 100644 --- a/src/MixAssembler/Finding/ValidationFinding.cs +++ b/src/MixAssembler/Finding/ValidationFinding.cs @@ -1,17 +1,14 @@ -using MixLib.Misc; +using MixLib.Misc; namespace MixAssembler.Finding { - public class ValidationFinding : AssemblyFinding + public class ValidationFinding(Severity severity, int lineNumber, LineSection lineSection, int causeStartIndex, int causeLength, ValidationError error) + : AssemblyFinding(severity, lineNumber, lineSection, causeStartIndex, causeLength) { - public ValidationError Error { get; private set; } - - public ValidationFinding(Severity severity, int lineNumber, LineSection lineSection, int causeStartIndex, int causeLength, ValidationError error) - : base(severity, lineNumber, lineSection, causeStartIndex, causeLength) - => Error = error; + public ValidationError Error => error; public override string Message - => Error.CompiledMessage; + => Error.CompiledMessage; } } diff --git a/src/MixAssembler/Instruction/LoaderInstructionParameters.cs b/src/MixAssembler/Instruction/LoaderInstructionParameters.cs index 7695058..1dc3c2d 100644 --- a/src/MixAssembler/Instruction/LoaderInstructionParameters.cs +++ b/src/MixAssembler/Instruction/LoaderInstructionParameters.cs @@ -5,28 +5,19 @@ namespace MixAssembler.Instruction { - /// - /// This class contains the parameters that are required to create an instance object of a specific loader instruction "template". - /// - /// The (static) ParseAddressField method is to be called during the parsing of the MIXAL source (first assembly pass), to create a parameter object based on the loader instruction's address field. - /// The CreateInstance method should be called during the second assembly pass, to create the actual loader instruction instance. - /// - public class LoaderInstructionParameters : IInstructionParameters + /// + /// This class contains the parameters that are required to create an instance object of a specific loader instruction "template". + /// + /// The (static) ParseAddressField method is to be called during the parsing of the MIXAL source (first assembly pass), to create a parameter object based on the loader instruction's address field. + /// The CreateInstance method should be called during the second assembly pass, to create the actual loader instruction instance. + /// + /// + /// Constructor for this class. + /// + /// The parameter value associated with the instruction. The type of the value depends on the loader instruction it is connected with + /// The length (character count) of the value in the source code it was parsed from + public class LoaderInstructionParameters(IValue value, int textLength) : IInstructionParameters { - private readonly int textLength; - private readonly IValue value; - - /// - /// Constructor for this class. - /// - /// The parameter value associated with the instruction. The type of the value depends on the loader instruction it is connected with - /// The length (character count) of the value in the source code it was parsed from - public LoaderInstructionParameters(IValue value, int textLength) - { - this.value = value; - this.textLength = textLength; - } - /// /// Create a loader instruction instance with the parameters contained in this object. /// @@ -40,11 +31,11 @@ public InstructionInstanceBase CreateInstance(InstructionBase instruction, Assem if (!value.IsValueDefined(status.LocationCounter)) { - status.ReportParsingError(LineSection.AddressField, 0, this.textLength, "value is not defined"); + status.ReportParsingError(LineSection.AddressField, 0, textLength, "value is not defined"); return null; } - return new LoaderInstruction.Instance(loaderInstruction, this.value.GetSign(status.LocationCounter), this.value.GetMagnitude(status.LocationCounter)); + return new LoaderInstruction.Instance(loaderInstruction, value.GetSign(status.LocationCounter), value.GetMagnitude(status.LocationCounter)); } /// diff --git a/src/MixAssembler/Instruction/MixInstructionParameters.cs b/src/MixAssembler/Instruction/MixInstructionParameters.cs index b1ac504..814f85c 100644 --- a/src/MixAssembler/Instruction/MixInstructionParameters.cs +++ b/src/MixAssembler/Instruction/MixInstructionParameters.cs @@ -11,42 +11,25 @@ namespace MixAssembler.Instruction /// The (static) ParseAddressField method is to be called during the parsing of the MIXAL source (first assembly pass), to create a parameter object based on the MIX instruction's address field. /// The CreateInstance method should be called during the second assembly pass, to create the actual MIX instruction instance. /// - public class MixInstructionParameters : IInstructionParameters + public class MixInstructionParameters(IValue address, int indexPartCharIndex, IValue index, int fieldPartCharIndex, IValue field, int textLength) : IInstructionParameters { - private readonly IValue address; - private readonly IValue field; - private readonly int fieldPartCharIndex; - private readonly IValue index; - private readonly int indexPartCharIndex; - private readonly int textLength; - - private MixInstructionParameters(IValue address, int indexPartCharIndex, IValue index, int fieldPartCharIndex, IValue field, int textLength) - { - this.address = address; - this.index = index; - this.field = field; - this.indexPartCharIndex = indexPartCharIndex; - this.fieldPartCharIndex = fieldPartCharIndex; - this.textLength = textLength; - } - private bool AreValuesDefined(AssemblingStatus status) { - if (!this.address.IsValueDefined(status.LocationCounter)) + if (!address.IsValueDefined(status.LocationCounter)) { - status.ReportParsingError(LineSection.AddressField, 0, this.indexPartCharIndex, "address value undefined"); + status.ReportParsingError(LineSection.AddressField, 0, indexPartCharIndex, "address value undefined"); return false; } - if (!this.index.IsValueDefined(status.LocationCounter)) + if (!index.IsValueDefined(status.LocationCounter)) { - status.ReportParsingError(LineSection.AddressField, this.indexPartCharIndex, this.fieldPartCharIndex - this.indexPartCharIndex, "index value undefined"); + status.ReportParsingError(LineSection.AddressField, indexPartCharIndex, fieldPartCharIndex - indexPartCharIndex, "index value undefined"); return false; } - if (!this.address.IsValueDefined(status.LocationCounter)) + if (!address.IsValueDefined(status.LocationCounter)) { - status.ReportParsingError(LineSection.AddressField, this.fieldPartCharIndex, this.textLength - this.fieldPartCharIndex, "field value undefined"); + status.ReportParsingError(LineSection.AddressField, fieldPartCharIndex, textLength - fieldPartCharIndex, "field value undefined"); return false; } @@ -67,11 +50,11 @@ public InstructionInstanceBase CreateInstance(InstructionBase instruction, Assem if (!AreValuesDefined(status)) return null; - var addressMagnitude = this.address.GetMagnitude(status.LocationCounter); + var addressMagnitude = address.GetMagnitude(status.LocationCounter); var word = new Word(MixInstruction.AddressByteCount); if (addressMagnitude > word.MaxMagnitude) { - status.ReportError(LineSection.AddressField, 0, this.indexPartCharIndex, new MixAssembler.Finding.ParsingError("address value " + addressMagnitude + " invalid", (int)-word.MaxMagnitude, (int)word.MaxMagnitude)); + status.ReportError(LineSection.AddressField, 0, indexPartCharIndex, new Finding.ParsingError("address value " + addressMagnitude + " invalid", (int)-word.MaxMagnitude, (int)word.MaxMagnitude)); return null; } @@ -82,13 +65,13 @@ public InstructionInstanceBase CreateInstance(InstructionBase instruction, Assem var instructionWord = new FullWord { - Sign = this.address.GetSign(status.LocationCounter) + Sign = address.GetSign(status.LocationCounter) }; for (int i = 0; i < word.ByteCount; i++) instructionWord[i] = word[i]; - instructionWord[MixInstruction.IndexByte] = (int)this.index.GetValue(status.LocationCounter); + instructionWord[MixInstruction.IndexByte] = (int)index.GetValue(status.LocationCounter); instructionWord[MixInstruction.FieldSpecByte] = fieldSpecValue; instructionWord[MixInstruction.OpcodeByte] = mixInstruction.Opcode; @@ -100,7 +83,7 @@ public InstructionInstanceBase CreateInstance(InstructionBase instruction, Assem private MixByte GetFieldSpecValue(AssemblingStatus status, MixInstruction mixInstruction) { - var fieldValue = this.field.GetValue(status.LocationCounter); + var fieldValue = field.GetValue(status.LocationCounter); switch (mixInstruction.MetaFieldSpec.Presence) { @@ -108,7 +91,7 @@ private MixByte GetFieldSpecValue(AssemblingStatus status, MixInstruction mixIns if (fieldValue == long.MinValue) return mixInstruction.FieldSpec.MixByteValue; - status.ReportParsingError(LineSection.AddressField, this.fieldPartCharIndex, this.textLength - this.fieldPartCharIndex, "fieldspec forbidden for this instruction"); + status.ReportParsingError(LineSection.AddressField, fieldPartCharIndex, textLength - fieldPartCharIndex, "fieldspec forbidden for this instruction"); return null; case MetaFieldSpec.Presences.Optional: @@ -121,7 +104,7 @@ private MixByte GetFieldSpecValue(AssemblingStatus status, MixInstruction mixIns if (fieldValue != long.MinValue) return (int)fieldValue; - status.ReportParsingError(LineSection.AddressField, this.fieldPartCharIndex, this.textLength - this.fieldPartCharIndex, "fieldspec mandatory for this instruction"); + status.ReportParsingError(LineSection.AddressField, fieldPartCharIndex, textLength - fieldPartCharIndex, "fieldspec mandatory for this instruction"); return null; } return null; @@ -130,12 +113,12 @@ private MixByte GetFieldSpecValue(AssemblingStatus status, MixInstruction mixIns /// /// Creates an instance of this class by parsing the address field of a MIX instruction. /// - /// MixInstruction to parse the address field for. This method will throw an exception if this parameter is of a different instruction type. /// The address field to parse. /// ParsingStatus object reflecting the current state of the parse process + /// /// - public static IInstructionParameters ParseAddressField(InstructionBase instruction, string addressField, ParsingStatus status) - { + public static IInstructionParameters ParseAddressField(string addressField, ParsingStatus status) + { var indexCharIndex = addressField.IndexOf(','); var sectionCharIndex = addressField.IndexOf('(', Math.Max(indexCharIndex, 0)); @@ -145,7 +128,7 @@ public static IInstructionParameters ParseAddressField(InstructionBase instructi if (indexCharIndex == -1) indexCharIndex = sectionCharIndex; - var address = APartValue.ParseValue(addressField.Substring(0, indexCharIndex), 0, status); + var address = APartValue.ParseValue(addressField[..indexCharIndex], 0, status); if (address == null) { status.ReportParsingError(0, indexCharIndex, "unable to parse address"); @@ -185,17 +168,17 @@ private void ReportInstanceErrors(AssemblingStatus status, MixInstruction.Instan { case InstanceValidationError.Sources.Address: causeStartIndex = 0; - causeLength = this.indexPartCharIndex; + causeLength = indexPartCharIndex; break; case InstanceValidationError.Sources.Index: - causeStartIndex = this.indexPartCharIndex; - causeLength = this.fieldPartCharIndex - this.indexPartCharIndex; + causeStartIndex = indexPartCharIndex; + causeLength = fieldPartCharIndex - indexPartCharIndex; break; case InstanceValidationError.Sources.FieldSpec: - causeStartIndex = this.fieldPartCharIndex; - causeLength = this.textLength - this.fieldPartCharIndex; + causeStartIndex = fieldPartCharIndex; + causeLength = textLength - fieldPartCharIndex; break; } diff --git a/src/MixAssembler/Instruction/ParsedSourceLine.cs b/src/MixAssembler/Instruction/ParsedSourceLine.cs index 72e882e..987badf 100644 --- a/src/MixAssembler/Instruction/ParsedSourceLine.cs +++ b/src/MixAssembler/Instruction/ParsedSourceLine.cs @@ -1,44 +1,29 @@ -using MixLib.Instruction; +using MixLib.Instruction; namespace MixAssembler.Instruction { /// /// Instances of this class represent a parsed line of MIXAL source code. Note that the fact that a source code line is parsed /// does not mean that the instruction is valid. + /// + /// The primary constructor creates an instance of this class that represents a (potentially) executable instruction. Note that the + /// instruction does not necessarily have to be executable by MIX; it can also concern a loader instruction, for instance. In + /// addition, the instruction may be invalid. /// - public class ParsedSourceLine : PreInstruction + public class ParsedSourceLine(int lineNumber, string locationField, string opField, string addressField, string comment, InstructionBase instruction, IInstructionParameters parameters) + : PreInstruction(instruction, parameters) { - public string AddressField { get; private set; } - public string Comment { get; private set; } - public int LineNumber { get; private set; } - public string LocationField { get; private set; } - public string OpField { get; private set; } + public string AddressField => addressField; + public string Comment => comment; + public int LineNumber => lineNumber; + public string LocationField => locationField; + public string OpField => opField; /// /// Creates a instance of this class that represents a comment line. /// - public ParsedSourceLine(int lineNumber, string comment) : base(null, null) + public ParsedSourceLine(int lineNumber, string comment) : this(lineNumber, null, null, null, comment, null, null) { - LineNumber = lineNumber; - LocationField = null; - OpField = null; - AddressField = null; - Comment = comment; - } - - /// - /// Creates an instance of this class that represents a (potentially) executable instruction. Note that the instruction does not - /// necessarily have to be executable by MIX; it can also concern a loader instruction, for instance. In addition, the instruction - /// may be invalid. - /// - public ParsedSourceLine(int lineNumber, string locationField, string opField, string addressField, string comment, InstructionBase instruction, IInstructionParameters parameters) - : base(instruction, parameters) - { - LineNumber = lineNumber; - LocationField = locationField; - OpField = opField; - AddressField = addressField; - Comment = comment; } public bool IsCommentLine diff --git a/src/MixAssembler/Instruction/PreInstruction.cs b/src/MixAssembler/Instruction/PreInstruction.cs index 866c2ad..e33532f 100644 --- a/src/MixAssembler/Instruction/PreInstruction.cs +++ b/src/MixAssembler/Instruction/PreInstruction.cs @@ -1,4 +1,4 @@ -using MixLib.Instruction; +using MixLib.Instruction; namespace MixAssembler.Instruction { @@ -6,16 +6,10 @@ namespace MixAssembler.Instruction /// This class represents an instruction that has been parsed (first assembly pass), but not yet assembled. /// Specifically, it contains an instruction "template" and the parameters required to create an actual instance of that instruction. /// - public class PreInstruction - { - public InstructionBase Instruction { get; private set; } - public IInstructionParameters Parameters { get; private set; } - - public PreInstruction(InstructionBase instruction, IInstructionParameters parameters) - { - Instruction = instruction; - Parameters = parameters; - } + public class PreInstruction(InstructionBase instruction, IInstructionParameters parameters) + { + public InstructionBase Instruction => instruction; + public IInstructionParameters Parameters => parameters; /// /// This property indicates if the PreInstruction can actually generate an instruction instance. For this to be the case, both an instruction template and diff --git a/src/MixAssembler/MixAssembler.csproj b/src/MixAssembler/MixAssembler.csproj index 7f3adaf..7e5bdde 100644 --- a/src/MixAssembler/MixAssembler.csproj +++ b/src/MixAssembler/MixAssembler.csproj @@ -1,6 +1,6 @@  - net6.0-windows + net8.0-windows7.0 Library diff --git a/src/MixAssembler/Parser.cs b/src/MixAssembler/Parser.cs index 8effabb..46c6525 100644 --- a/src/MixAssembler/Parser.cs +++ b/src/MixAssembler/Parser.cs @@ -129,7 +129,7 @@ private static void GetMixOrLoaderInstructionAndParameters(string opField, strin if (instruction != null) { - instructionParameters = MixInstructionParameters.ParseAddressField(instruction, addressField, status); + instructionParameters = MixInstructionParameters.ParseAddressField(addressField, status); status.LocationCounter++; } } @@ -224,7 +224,7 @@ public static PreInstruction[] ParseSource(string[] sourceLines, ParsingStatus s if (endLineNumber == -1) { status.Findings.Add(new AssemblyError(int.MinValue, LineSection.CommentField, 0, 0, new ParsingError("END operation is mandatory but not included"))); - return preInstructions.ToArray(); + return [.. preInstructions]; } // all symbols that are not yet defined at the end of the parsing process are treated as if " CON *" instructions were included just before the END instruction @@ -240,7 +240,7 @@ public static PreInstruction[] ParseSource(string[] sourceLines, ParsingStatus s endLineNumber++; } - return preInstructions.ToArray(); + return [.. preInstructions]; } private static string[] SplitLine(string sourceLine) @@ -249,23 +249,23 @@ private static string[] SplitLine(string sourceLine) var searchBeyondIndex = FindFirstWhiteSpace(sourceLine, -1); if (searchBeyondIndex == -1) - return new string[] { sourceLine, string.Empty, string.Empty, string.Empty }; + return [sourceLine, string.Empty, string.Empty, string.Empty]; var opFieldStart = FindFirstNonWhiteSpace(sourceLine, searchBeyondIndex); if (opFieldStart == -1) - return new string[] { sourceLine[..searchBeyondIndex], string.Empty, string.Empty, string.Empty }; + return [sourceLine[..searchBeyondIndex], string.Empty, string.Empty, string.Empty]; var opFieldEnd = FindFirstWhiteSpace(sourceLine, opFieldStart); if (opFieldEnd == -1) - return new string[] { sourceLine[..searchBeyondIndex], sourceLine[opFieldStart..], string.Empty, string.Empty }; + return [sourceLine[..searchBeyondIndex], sourceLine[opFieldStart..], string.Empty, string.Empty]; int opFieldLength = opFieldEnd - opFieldStart; var addressFieldStart = FindFirstNonWhiteSpace(sourceLine, opFieldEnd); if (addressFieldStart == -1) - return new string[] { sourceLine[..searchBeyondIndex], sourceLine.Substring(opFieldStart, opFieldLength), string.Empty, string.Empty }; + return [sourceLine[..searchBeyondIndex], sourceLine.Substring(opFieldStart, opFieldLength), string.Empty, string.Empty]; if (sourceLine[addressFieldStart] == '"') { @@ -280,15 +280,15 @@ private static string[] SplitLine(string sourceLine) addressFieldEnd = FindFirstWhiteSpace(sourceLine, addressFieldStart); if (addressFieldEnd == -1) - return new string[] { sourceLine[..searchBeyondIndex], sourceLine.Substring(opFieldStart, opFieldLength), sourceLine[addressFieldStart..], string.Empty }; + return [sourceLine[..searchBeyondIndex], sourceLine.Substring(opFieldStart, opFieldLength), sourceLine[addressFieldStart..], string.Empty]; int addressFieldLength = addressFieldEnd - addressFieldStart; var commentFieldStart = FindFirstNonWhiteSpace(sourceLine, addressFieldEnd); if (commentFieldStart == -1) - return new string[] { sourceLine[..searchBeyondIndex], sourceLine.Substring(opFieldStart, opFieldLength), sourceLine.Substring(addressFieldStart, addressFieldLength), "" }; + return [sourceLine[..searchBeyondIndex], sourceLine.Substring(opFieldStart, opFieldLength), sourceLine.Substring(addressFieldStart, addressFieldLength), ""]; - return new string[] { sourceLine[..searchBeyondIndex], sourceLine.Substring(opFieldStart, opFieldLength), sourceLine.Substring(addressFieldStart, addressFieldLength), sourceLine[commentFieldStart..] }; + return [sourceLine[..searchBeyondIndex], sourceLine.Substring(opFieldStart, opFieldLength), sourceLine.Substring(addressFieldStart, addressFieldLength), sourceLine[commentFieldStart..]]; } } } diff --git a/src/MixAssembler/ParsingStatus.cs b/src/MixAssembler/ParsingStatus.cs index 2b43963..d51423b 100644 --- a/src/MixAssembler/ParsingStatus.cs +++ b/src/MixAssembler/ParsingStatus.cs @@ -1,17 +1,14 @@ -using MixLib.Type; +using MixLib.Type; namespace MixAssembler { - public class ParsingStatus : AssemblingStatus + public class ParsingStatus(SymbolCollection symbols) : AssemblingStatus { public LineSection LineSection { get; set; } = LineSection.LocationField; - public SymbolCollection Symbols { get; private set; } + public SymbolCollection Symbols { get; private set; } = symbols ?? []; public ParsingStatus() : this(null) { } - public ParsingStatus(SymbolCollection symbols) - => Symbols = symbols ?? new SymbolCollection(); - public void ReportParsingError(int causeStartIndex, int causeLength, string message) => ReportParsingError(LineSection, causeStartIndex, causeLength, message); diff --git a/src/MixAssembler/Symbol/LiteralConstantSymbol.cs b/src/MixAssembler/Symbol/LiteralConstantSymbol.cs index 11a1477..99fbb82 100644 --- a/src/MixAssembler/Symbol/LiteralConstantSymbol.cs +++ b/src/MixAssembler/Symbol/LiteralConstantSymbol.cs @@ -3,34 +3,23 @@ namespace MixAssembler.Symbol { - public class LiteralConstantSymbol : SymbolBase + public class LiteralConstantSymbol(Word.Signs literalSign, long literalMagnitude, string name) : SymbolBase(name) { - private readonly long literalMagnitude; - private readonly Word.Signs literalSign; private long magnitude; private Word.Signs sign; private bool valueDefined; - private LiteralConstantSymbol(Word.Signs literalSign, long literalMagnitude, string name) : base(name) - { - this.literalSign = literalSign; - this.literalMagnitude = literalMagnitude; - this.magnitude = -1L; - this.sign = Word.Signs.Positive; - this.valueDefined = false; - } - public override bool IsSymbolDefined => this.valueDefined; public override long MemoryWordMagnitude - => this.literalMagnitude; + => literalMagnitude; public override Word.Signs MemoryWordSign - => this.literalSign; + => literalSign; public override long MemoryWordValue - => this.literalSign.ApplyTo(this.literalMagnitude); + => literalSign.ApplyTo(literalMagnitude); public override long GetValue(int currentAddress) => this.sign.ApplyTo(this.magnitude); diff --git a/src/MixAssembler/Symbol/LocalSymbol.cs b/src/MixAssembler/Symbol/LocalSymbol.cs index dea8ee5..174ee0a 100644 --- a/src/MixAssembler/Symbol/LocalSymbol.cs +++ b/src/MixAssembler/Symbol/LocalSymbol.cs @@ -17,7 +17,7 @@ public LocalSymbol(int index) : base(index.ToString()) if (index < 0 || index > 9) throw new ArgumentException("index must be between 0 and 9"); - this.addresses = new List(); + this.addresses = []; } public override bool IsMultiValuedSymbol @@ -83,7 +83,7 @@ public static IValue ParseValue(string text, int sectionCharIndex, ParsingStatus status.Symbols.Add(symbol); } - if (!(symbol is LocalSymbol)) + if (symbol is not LocalSymbol) { status.ReportParsingError(sectionCharIndex, 1, "non-local symbol named " + localSymbolChar + " already defined, unable to refer to it"); return symbol; @@ -113,18 +113,12 @@ public override long GetMagnitude(int currentAddress) public override Word.Signs GetSign(int currentAddress) => throw new NotImplementedException(); - private class Reference : IValue + private class Reference(LocalSymbol referee, Reference.Directions direction) : IValue { - private readonly Directions mDirection; - private readonly LocalSymbol mReferee; - - public Reference(LocalSymbol referee, Directions direction) - { - mReferee = referee; - mDirection = direction; - } + private readonly Directions mDirection = direction; + private readonly LocalSymbol mReferee = referee; - public long GetMagnitude(int currentAddress) + public long GetMagnitude(int currentAddress) => GetValue(currentAddress); public Word.Signs GetSign(int currentAddress) diff --git a/src/MixAssembler/Symbol/ValueSymbol.cs b/src/MixAssembler/Symbol/ValueSymbol.cs index ce8ab1c..ff12274 100644 --- a/src/MixAssembler/Symbol/ValueSymbol.cs +++ b/src/MixAssembler/Symbol/ValueSymbol.cs @@ -3,22 +3,16 @@ namespace MixAssembler.Symbol { - public class ValueSymbol : SymbolBase, IValueSymbol + public class ValueSymbol(string name) : SymbolBase(name), IValueSymbol { public const long MaxValue = (1 << MixByte.BitCount * MixInstruction.AddressByteCount) - 1; public const long MinValue = -MaxValue; public const int MaxNameLength = 10; - private bool isDefined; + private bool isDefined = false; public long Magnitude { get; private set; } - public Word.Signs Sign { get; private set; } - - public ValueSymbol(string name) : base(name) - { - this.isDefined = false; - Sign = Word.Signs.Positive; - } + public Word.Signs Sign { get; private set; } = Word.Signs.Positive; public override bool IsSymbolDefined => this.isDefined; diff --git a/src/MixAssembler/Value/ExpressionValue.cs b/src/MixAssembler/Value/ExpressionValue.cs index 85bc7af..6fa7af8 100644 --- a/src/MixAssembler/Value/ExpressionValue.cs +++ b/src/MixAssembler/Value/ExpressionValue.cs @@ -25,22 +25,22 @@ static ExpressionValue() binaryOperations[":"] = DoCalculateField; } - private static IValue DoAdd(IValue left, IValue right, int currentAddress) - => new NumberValue((left.GetValue(currentAddress) + right.GetValue(currentAddress)) % FullWordModulusMask); + private static NumberValue DoAdd(IValue left, IValue right, int currentAddress) + => new((left.GetValue(currentAddress) + right.GetValue(currentAddress)) % FullWordModulusMask); - private static IValue DoCalculateField(IValue left, IValue right, int currentAddress) - => new NumberValue(((left.GetValue(currentAddress) * 8L) + right.GetValue(currentAddress)) % FullWordModulusMask); + private static NumberValue DoCalculateField(IValue left, IValue right, int currentAddress) + => new(((left.GetValue(currentAddress) * 8L) + right.GetValue(currentAddress)) % FullWordModulusMask); - private static IValue DoDivide(IValue left, IValue right, int currentAddress) - => new NumberValue(left.GetValue(currentAddress) / right.GetValue(currentAddress) % FullWordModulusMask); + private static NumberValue DoDivide(IValue left, IValue right, int currentAddress) + => new(left.GetValue(currentAddress) / right.GetValue(currentAddress) % FullWordModulusMask); - private static IValue DoMultiply(IValue left, IValue right, int currentAddress) - => new NumberValue(left.GetValue(currentAddress) * right.GetValue(currentAddress) % FullWordModulusMask); + private static NumberValue DoMultiply(IValue left, IValue right, int currentAddress) + => new(left.GetValue(currentAddress) * right.GetValue(currentAddress) % FullWordModulusMask); - private static IValue DoSubstract(IValue left, IValue right, int currentAddress) - => new NumberValue((left.GetValue(currentAddress) - right.GetValue(currentAddress)) % FullWordModulusMask); + private static NumberValue DoSubstract(IValue left, IValue right, int currentAddress) + => new((left.GetValue(currentAddress) - right.GetValue(currentAddress)) % FullWordModulusMask); - private static IValue DoFractionDivide(IValue left, IValue right, int currentAddress) + private static NumberValue DoFractionDivide(IValue left, IValue right, int currentAddress) { var divider = new decimal(left.GetValue(currentAddress)); divider *= FullWordModulusMask; @@ -101,7 +101,7 @@ public static IValue ParseValue(string text, int sectionCharIndex, ParsingStatus int rightTermStartIndex = operatorPosition + operatorText.Length; // the left term can itself be an expression, so parse it as one (recursively) - var left = ParseValue(text.Substring(0, operatorPosition), sectionCharIndex, status); + var left = ParseValue(text[..operatorPosition], sectionCharIndex, status); // the right term must be an atomic expression var right = AtomicExpressionValue.ParseValue(text[rightTermStartIndex..], sectionCharIndex + rightTermStartIndex, status); diff --git a/src/MixAssembler/Value/WValue.cs b/src/MixAssembler/Value/WValue.cs index ad030c9..be80f01 100644 --- a/src/MixAssembler/Value/WValue.cs +++ b/src/MixAssembler/Value/WValue.cs @@ -1,4 +1,4 @@ -using MixLib.Type; +using MixLib.Type; namespace MixAssembler.Value { @@ -10,7 +10,7 @@ public static class WValue public static IValue ParseValue(string text, int sectionCharIndex, ParsingStatus status) { // split the text to parse in its W-value components - var textParts = text.Split(new char[] { ',' }); + var textParts = text.Split([',']); int currentIndex = 0; var register = new FullWordRegister(); @@ -21,7 +21,7 @@ public static IValue ParseValue(string text, int sectionCharIndex, ParsingStatus { // parse the address part... var braceIndex = part.IndexOf('('); - var address = ExpressionValue.ParseValue((braceIndex == -1) ? part : part.Substring(0, braceIndex), sectionCharIndex + currentIndex, status); + var address = ExpressionValue.ParseValue((braceIndex == -1) ? part : part[..braceIndex], sectionCharIndex + currentIndex, status); if (address == null) return null; diff --git a/src/MixEmul/Components/AssemblyFindingListView.cs b/src/MixEmul/Components/AssemblyFindingListView.cs index 255cdfc..940aa4b 100644 --- a/src/MixEmul/Components/AssemblyFindingListView.cs +++ b/src/MixEmul/Components/AssemblyFindingListView.cs @@ -29,7 +29,7 @@ public AssemblyFindingListView() mMessageColumn.Width = 400; mFindingsListView.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Top; - mFindingsListView.Columns.AddRange(new ColumnHeader[] { mSeverityColumn, mLineNumberColumn, mMessageColumn }); + mFindingsListView.Columns.AddRange([mSeverityColumn, mLineNumberColumn, mMessageColumn]); mFindingsListView.FullRowSelect = true; mFindingsListView.GridLines = true; mFindingsListView.Location = new Point(0, 0); diff --git a/src/MixEmul/Components/DeviceStatusControl.cs b/src/MixEmul/Components/DeviceStatusControl.cs index ea5355e..cd818c0 100644 --- a/src/MixEmul/Components/DeviceStatusControl.cs +++ b/src/MixEmul/Components/DeviceStatusControl.cs @@ -59,7 +59,7 @@ public DeviceStatusControl(MixDevice device) this.resetMenuItem.Text = "Reset"; this.resetMenuItem.Click += ResetMenuItem_Click; - this.contextMenuStrip.Items.AddRange(new ToolStripItem[] { this.inputMenuItem, this.outputMenuItem, this.contextSeparator, this.resetMenuItem }); + this.contextMenuStrip.Items.AddRange([this.inputMenuItem, this.outputMenuItem, this.contextSeparator, this.resetMenuItem]); ContextMenuStrip = this.contextMenuStrip; Controls.Add(this.indexLabel); diff --git a/src/MixEmul/Components/DevicesControl.cs b/src/MixEmul/Components/DevicesControl.cs index 95ea5a3..6d7c967 100644 --- a/src/MixEmul/Components/DevicesControl.cs +++ b/src/MixEmul/Components/DevicesControl.cs @@ -237,27 +237,19 @@ public ToolTip ToolTip } } - public class LayoutStructure - { - private readonly SortedList mLayoutList; + public class LayoutStructure(DevicesControl.Orientations orientation, int horizontalSpacing, int verticalSpacing) + { + private readonly SortedList mLayoutList = []; - public Orientations Orientation { get; set; } - public int HorizontalSpacing { get; set; } - public int VerticalSpacing { get; set; } + public Orientations Orientation { get; set; } = orientation; + public int HorizontalSpacing { get; set; } = horizontalSpacing; + public int VerticalSpacing { get; set; } = verticalSpacing; public LayoutStructure(Orientations orientation) : this(orientation, 0, 0) { } - public LayoutStructure(Orientations orientation, int horizontalSpacing, int verticalSpacing) - { - mLayoutList = new SortedList(); - Orientation = orientation; - HorizontalSpacing = horizontalSpacing; - VerticalSpacing = verticalSpacing; - } - public Breaks this[int location] { - get => !mLayoutList.ContainsKey(location) ? Breaks.None : mLayoutList[location]; + get => !mLayoutList.TryGetValue(location, out var value) ? Breaks.None : value; set { if (mLayoutList.ContainsKey(location)) diff --git a/src/MixEmul/Components/EditorList.cs b/src/MixEmul/Components/EditorList.cs index c7ee065..5e759e0 100644 --- a/src/MixEmul/Components/EditorList.cs +++ b/src/MixEmul/Components/EditorList.cs @@ -44,7 +44,7 @@ public EditorList(int minIndex = 0, int maxIndex = -1, CreateEditorCallback crea this.sizeAdaptationPending = false; this.editorsSyncRoot = new object(); - this.editors = new List(); + this.editors = []; InitializeComponent(); } @@ -424,7 +424,7 @@ public int FirstVisibleIndex int indexDelta = value - this.firstVisibleIndex; int selectedEditorIndex = ActiveEditorIndex; - FieldTypes? field = selectedEditorIndex >= 0 ? this.editors[selectedEditorIndex].FocusedField : null; + FieldTypes? @field = selectedEditorIndex >= 0 ? this.editors[selectedEditorIndex].FocusedField : null; int? caretIndex = selectedEditorIndex >= 0 ? this.editors[selectedEditorIndex].CaretIndex : null; this.firstVisibleIndex = value; @@ -453,7 +453,7 @@ public int FirstVisibleIndex else if (selectedEditorIndex >= VisibleEditorCount) selectedEditorIndex = VisibleEditorCount - 1; - this.editors[selectedEditorIndex].Focus(field, caretIndex); + this.editors[selectedEditorIndex].Focus(@field, caretIndex); } IsReloading = false; @@ -523,12 +523,9 @@ public int MinIndex } } - public class FirstVisibleIndexChangedEventArgs : EventArgs + public class FirstVisibleIndexChangedEventArgs(int firstVisibleIndex) : EventArgs { - public int FirstVisibleIndex { get; private set; } - - public FirstVisibleIndexChangedEventArgs(int firstVisibleIndex) - => FirstVisibleIndex = firstVisibleIndex; + public int FirstVisibleIndex { get; private set; } = firstVisibleIndex; } } diff --git a/src/MixEmul/Components/FieldKeyEventArgs.cs b/src/MixEmul/Components/FieldKeyEventArgs.cs index 1e623cc..9f20b75 100644 --- a/src/MixEmul/Components/FieldKeyEventArgs.cs +++ b/src/MixEmul/Components/FieldKeyEventArgs.cs @@ -3,13 +3,10 @@ namespace MixGui.Components { - public class FieldKeyEventArgs : IndexKeyEventArgs + public class FieldKeyEventArgs(Keys keyData, FieldTypes field, int? index) : IndexKeyEventArgs(keyData, index) { - public FieldTypes Field { get; private set; } + public FieldTypes Field => @field; public FieldKeyEventArgs(Keys keyData, FieldTypes field) : this(keyData, field, null) { } - - public FieldKeyEventArgs(Keys keyData, FieldTypes field, int? index) : base(keyData, index) - => Field = field; - } + } } diff --git a/src/MixEmul/Components/IndexKeyEventArgs.cs b/src/MixEmul/Components/IndexKeyEventArgs.cs index a51d59b..6aa7ec6 100644 --- a/src/MixEmul/Components/IndexKeyEventArgs.cs +++ b/src/MixEmul/Components/IndexKeyEventArgs.cs @@ -2,11 +2,8 @@ namespace MixGui.Components { - public class IndexKeyEventArgs : KeyEventArgs + public class IndexKeyEventArgs(Keys keyData, int? index) : KeyEventArgs(keyData) { - public int? Index { get; private set; } - - public IndexKeyEventArgs(Keys keyData, int? index) : base(keyData) - => Index = index; - } + public int? Index => index; + } } diff --git a/src/MixEmul/Components/LinkedItemsSelectorControl.cs b/src/MixEmul/Components/LinkedItemsSelectorControl.cs index 260297f..ca7d3cd 100644 --- a/src/MixEmul/Components/LinkedItemsSelectorControl.cs +++ b/src/MixEmul/Components/LinkedItemsSelectorControl.cs @@ -196,26 +196,16 @@ public void Clear() } } - public class ItemSelectedEventArgs : EventArgs + public class ItemSelectedEventArgs(T selectedItem) : EventArgs { - public ItemSelectedEventArgs(T selectedItem) - => SelectedItem = selectedItem; - - public T SelectedItem { get; private set; } - } - - public class LinkedItem - { - public LinkedItem Previous { get; set; } - public LinkedItem Next { get; set; } - public T Item { get; private set; } - - public LinkedItem(LinkedItem previous, T item, LinkedItem next) - { - Previous = previous; - Item = item; - Next = next; - } + public T SelectedItem { get; private set; } = selectedItem; + } + + public class LinkedItem(LinkedItem previous, T item, LinkedItem next) + { + public LinkedItem Previous { get; set; } = previous; + public LinkedItem Next { get; set; } = next; + public T Item { get; private set; } = item; public LinkedItem(LinkedItem previous, T item) : this(previous, item, null) { } diff --git a/src/MixEmul/Components/LogListView.cs b/src/MixEmul/Components/LogListView.cs index 44f300c..3853680 100644 --- a/src/MixEmul/Components/LogListView.cs +++ b/src/MixEmul/Components/LogListView.cs @@ -42,7 +42,7 @@ public LogListView() this.messageColumn.Width = 400; this.listView.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Top; - this.listView.Columns.AddRange(new ColumnHeader[] { this.severityColumn, this.moduleColumn, this.addressColumn, this.titleColumn, this.messageColumn }); + this.listView.Columns.AddRange([this.severityColumn, this.moduleColumn, this.addressColumn, this.titleColumn, this.messageColumn]); this.listView.HeaderStyle = ColumnHeaderStyle.Nonclickable; this.listView.FullRowSelect = true; this.listView.GridLines = true; diff --git a/src/MixEmul/Components/MemoryEditor.cs b/src/MixEmul/Components/MemoryEditor.cs index 50faee5..92c6402 100644 --- a/src/MixEmul/Components/MemoryEditor.cs +++ b/src/MixEmul/Components/MemoryEditor.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Drawing; +using System.Linq; using System.Windows.Forms; using MixGui.Events; using MixGui.Properties; @@ -46,7 +47,7 @@ public MemoryEditor(IMemory memory = null) this.profilingMaxCounts = new long[Enum.GetValues(typeof(GuiSettings.ProfilingInfoType)).Length]; - this.breakpoints = SortedList.Synchronized(new SortedList()); + this.breakpoints = SortedList.Synchronized([]); this.noMemoryLabel = new Label { @@ -100,7 +101,7 @@ public ToolTip ToolTip if (this.wordEditorList != null) { - foreach (MemoryWordEditor editor in this.wordEditorList) + foreach (MemoryWordEditor editor in this.wordEditorList.Cast()) editor.ToolTip = this.toolTip; } } @@ -159,7 +160,7 @@ private void BreakPointCheckedChanged(object sender, EventArgs e) public void ClearBreakpoints() { this.breakpoints.Clear(); - foreach (MemoryWordEditor editor in this.wordEditorList) + foreach (MemoryWordEditor editor in this.wordEditorList.Cast()) editor.BreakPointChecked = false; } @@ -334,8 +335,7 @@ private void SetDownButtonState(Memory memory) } } - if (this.nextDataIndex == null) - this.nextDataIndex = memory.FirstAddressWithContentsAfter(lastIndex); + this.nextDataIndex ??= memory.FirstAddressWithContentsAfter(lastIndex); } this.downButton.Enabled = this.nextDataIndex.HasValue; @@ -446,7 +446,7 @@ public IndexedAddressCalculatorCallback IndexedAddressCalculatorCallback if (this.wordEditorList != null) { - foreach (MemoryWordEditor wordEditor in this.wordEditorList) + foreach (MemoryWordEditor wordEditor in this.wordEditorList.Cast()) wordEditor.IndexedAddressCalculatorCallback = this.indexedAddressCalculatorCallback; } } @@ -592,7 +592,7 @@ public SymbolCollection Symbols if (this.wordEditorList != null) { - foreach (MemoryWordEditor editor in this.wordEditorList) + foreach (MemoryWordEditor editor in this.wordEditorList.Cast()) editor.Symbols = this.symbols; } } @@ -624,15 +624,12 @@ private void ExportButton_Click(object sender, EventArgs args) if (exportDialog.ShowDialog(this) != DialogResult.OK) return; - if (this.saveExportFileDialog == null) + this.saveExportFileDialog ??= new SaveFileDialog { - this.saveExportFileDialog = new SaveFileDialog - { - DefaultExt = "mixdeck", - Filter = "MixEmul card deck files|*.mixdeck|All files|*.*", - Title = "Specify export file name" - }; - } + DefaultExt = "mixdeck", + Filter = "MixEmul card deck files|*.mixdeck|All files|*.*", + Title = "Specify export file name" + }; if (this.saveExportFileDialog.ShowDialog(this) != DialogResult.OK) return; diff --git a/src/MixEmul/Components/MemoryWordEditor.cs b/src/MixEmul/Components/MemoryWordEditor.cs index 97c16f8..ac31058 100644 --- a/src/MixEmul/Components/MemoryWordEditor.cs +++ b/src/MixEmul/Components/MemoryWordEditor.cs @@ -42,8 +42,7 @@ public MemoryWordEditor(IMemoryFullWord memoryWord = null) this.readOnly = false; this.marked = false; - if (memoryWord == null) - memoryWord = new MemoryFullWord(int.MinValue); + memoryWord ??= new MemoryFullWord(int.MinValue); this.instructionTextBox = new InstructionInstanceTextBox(memoryWord); this.fullWordEditor = new FullWordEditor(memoryWord); diff --git a/src/MixEmul/Components/MixByteCollectionEditorList.cs b/src/MixEmul/Components/MixByteCollectionEditorList.cs index b6ed570..555858f 100644 --- a/src/MixEmul/Components/MixByteCollectionEditorList.cs +++ b/src/MixEmul/Components/MixByteCollectionEditorList.cs @@ -1,9 +1,8 @@  namespace MixGui.Components { - public class MixByteCollectionEditorList : EditorList + public class MixByteCollectionEditorList(int maxWordCount = 0, EditorList.CreateEditorCallback createEditor = null, EditorList.LoadEditorCallback loadEditor = null) + : EditorList(0, maxWordCount - 1, createEditor, loadEditor) { - public MixByteCollectionEditorList(int maxWordCount = 0, CreateEditorCallback createEditor = null, LoadEditorCallback loadEditor = null) - : base(0, maxWordCount - 1, createEditor, loadEditor) { } - } + } } diff --git a/src/MixEmul/Components/PreferencesForm.cs b/src/MixEmul/Components/PreferencesForm.cs index cfa9596..9a7aa9c 100644 --- a/src/MixEmul/Components/PreferencesForm.cs +++ b/src/MixEmul/Components/PreferencesForm.cs @@ -188,7 +188,7 @@ private void FillColorSelectionBox() list.Add(comboBoxItem); } - this.colorSelectionBox.Items.AddRange(list.ToArray()); + this.colorSelectionBox.Items.AddRange([.. list]); if (this.colorSelectionBox.Items.Count > 0) this.colorSelectionBox.SelectedIndex = 0; @@ -213,7 +213,7 @@ private void FillDeviceFileSelectionBox() list.Add(item); } - this.deviceFileSelectionBox.Items.AddRange(list.ToArray()); + this.deviceFileSelectionBox.Items.AddRange([.. list]); if (this.deviceFileSelectionBox.Items.Count > 0) this.deviceFileSelectionBox.SelectedIndex = 0; @@ -238,7 +238,7 @@ private void FillTickCountSelectionBox() list.Add(item); } - this.tickCountSelectionBox.Items.AddRange(list.ToArray()); + this.tickCountSelectionBox.Items.AddRange([.. list]); if (this.tickCountSelectionBox.Items.Count > 0) this.tickCountSelectionBox.SelectedIndex = 0; diff --git a/src/MixEmul/Components/SourceAndFindingsForm.cs b/src/MixEmul/Components/SourceAndFindingsForm.cs index cbc1974..29eeeaa 100644 --- a/src/MixEmul/Components/SourceAndFindingsForm.cs +++ b/src/MixEmul/Components/SourceAndFindingsForm.cs @@ -50,8 +50,7 @@ private void InitializeComponent() // // this.statusStrip // - this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.toolStripStatusLabel}); + this.statusStrip.Items.AddRange([this.toolStripStatusLabel]); this.statusStrip.Location = new System.Drawing.Point(0, 383); this.statusStrip.Name = "_statusStrip"; this.statusStrip.Size = new System.Drawing.Size(568, 22); diff --git a/src/MixEmul/Components/SymbolListView.cs b/src/MixEmul/Components/SymbolListView.cs index d975441..c76d3c5 100644 --- a/src/MixEmul/Components/SymbolListView.cs +++ b/src/MixEmul/Components/SymbolListView.cs @@ -116,7 +116,7 @@ private void ShowSymbol(SymbolBase symbol) if (valueSymbol.Sign.IsNegative()) valueText = '-' + valueText; - var viewItem = new ListViewItem(new string[] { valueSymbol.Name, valueText }) + var viewItem = new ListViewItem([valueSymbol.Name, valueText]) { Name = valueSymbol.Name }; diff --git a/src/MixEmul/Components/TeletypeForm.cs b/src/MixEmul/Components/TeletypeForm.cs index 6245e6a..1d0f8b9 100644 --- a/src/MixEmul/Components/TeletypeForm.cs +++ b/src/MixEmul/Components/TeletypeForm.cs @@ -130,8 +130,7 @@ private void InitializeComponent() // this.statusStrip.Location = new Point(0, 287); this.statusStrip.Name = "mStatusBar"; - this.statusStrip.Items.AddRange(new ToolStripItem[] { - this.toolStripStatusLabel}); + this.statusStrip.Items.AddRange([this.toolStripStatusLabel]); this.statusStrip.Size = new Size(616, 22); this.statusStrip.TabIndex = 5; // diff --git a/src/MixEmul/Components/TextFileDeviceEditor.cs b/src/MixEmul/Components/TextFileDeviceEditor.cs index 61100e9..c32145d 100644 --- a/src/MixEmul/Components/TextFileDeviceEditor.cs +++ b/src/MixEmul/Components/TextFileDeviceEditor.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Timers; using System.Windows.Forms; using MixGui.Settings; @@ -56,8 +57,8 @@ public TextFileDeviceEditor() this.lastLoadTime = DateTime.Now; this.ioDelayTimer.Interval = DeviceSettings.DeviceReloadInterval; - this.readBytes = new List(); - this.editBytes = new List(); + this.readBytes = []; + this.editBytes = []; SetDeviceRecordCount(1); @@ -206,7 +207,7 @@ private void SetDeviceRecordCount(int recordCount) this.indexCharCount = (recordCount - 1).ToString().Length; - foreach (DeviceMixByteCollectionEditor editor in this.mixByteCollectionEditorList) + foreach (DeviceMixByteCollectionEditor editor in this.mixByteCollectionEditorList.Cast()) editor.IndexCharCount = this.indexCharCount; ProcessSupportsAppending(); @@ -337,7 +338,7 @@ private bool LoadRecords(LoadErrorHandlingMode errorHandlingMode) stream.Close(); } else - readBytes = new List(); + readBytes = []; if (readBytes.Count == 0) readBytes.Add(new MixByteCollection(this.deviceBytesPerRecord)); diff --git a/src/MixEmul/Components/WordEditorList.cs b/src/MixEmul/Components/WordEditorList.cs index 44dff3172dba7aa2942779f50c46605847a97893..9b12c0f1a52baa5394124c10150aa0619ad2c860 100644 GIT binary patch literal 344 zcmZ`!%L;=q5IiSeu}6he+N+daq!huPdyX;CrFn>nAc$YqLqDm%P*H2_p@&`A*`1x4 z_w!}AmagVP!WFwqi%Dj6ZH+YE(VmjJEfoq7iaQ54+f?TYy=@9~K0@O`qsdJrI|kFl zyJZSz$2`zZN!Cd2<-Eeu) flLzxt<``1&cXZL7!S2Aov`WoAh8_kAV-55JvtW5& literal 674 zcmaKpPiw+J6vXG6g5M#>2rBKhNH3v?py!_BDm0j+Vj>9QS66>;iB!{V2yb`t{$$=v zu9r%gN^MkY2XdfTOXWIhrUUmxseb6#aaL3-HS`YjqLV)(DhI7p(Ce6Wpp1?h{Kd>( zYkd+qbN03X)!=JUIE$^4)p6%zbQ$hAm^GZ@)pJSB=Px_2%yi6$Ovw?$~Bd z#Mv{O=7{H6Z$E49{fhC=(41J~;nB1F)-p2BwG^i|_}FkhdX$p0Emz!5TXu8*befI@ pj%OYJ|9+tebPZdtO|ShYjt2ta?=0+ diff --git a/src/MixEmul/Events/AddressSelectedEventArgs.cs b/src/MixEmul/Events/AddressSelectedEventArgs.cs index 91d2bac..da71d53 100644 --- a/src/MixEmul/Events/AddressSelectedEventArgs.cs +++ b/src/MixEmul/Events/AddressSelectedEventArgs.cs @@ -2,11 +2,8 @@ { using System; - public class AddressSelectedEventArgs : EventArgs + public class AddressSelectedEventArgs(int selectedAddress) : EventArgs { - public int SelectedAddress { get; private set; } - - public AddressSelectedEventArgs(int selectedAddress) - => SelectedAddress = selectedAddress; - } + public int SelectedAddress => selectedAddress; + } } diff --git a/src/MixEmul/Events/DeviceEventArgs.cs b/src/MixEmul/Events/DeviceEventArgs.cs index ec79eb5..dc28842 100644 --- a/src/MixEmul/Events/DeviceEventArgs.cs +++ b/src/MixEmul/Events/DeviceEventArgs.cs @@ -3,11 +3,8 @@ namespace MixGui.Events { - public class DeviceEventArgs : EventArgs + public class DeviceEventArgs(MixDevice device) : EventArgs { - public MixDevice Device { get; private set; } - - public DeviceEventArgs(MixDevice device) - => Device = device; - } + public MixDevice Device => device; + } } diff --git a/src/MixEmul/Events/MixByteCollectionValueEditorChangedEventArgs.cs b/src/MixEmul/Events/MixByteCollectionValueEditorChangedEventArgs.cs index d7e788c..0948f67 100644 --- a/src/MixEmul/Events/MixByteCollectionValueEditorChangedEventArgs.cs +++ b/src/MixEmul/Events/MixByteCollectionValueEditorChangedEventArgs.cs @@ -1,17 +1,11 @@ -using System; +using System; using MixLib.Type; namespace MixGui.Events { - public class MixByteCollectionEditorValueChangedEventArgs : EventArgs + public class MixByteCollectionEditorValueChangedEventArgs(IMixByteCollection oldValue, IMixByteCollection newValue) : EventArgs { - public IMixByteCollection NewValue { get; private set; } - public IMixByteCollection OldValue { get; private set; } - - public MixByteCollectionEditorValueChangedEventArgs(IMixByteCollection oldValue, IMixByteCollection newValue) - { - OldValue = oldValue; - NewValue = newValue; - } - } + public IMixByteCollection NewValue => newValue; + public IMixByteCollection OldValue => oldValue; + } } diff --git a/src/MixEmul/Events/WordValueEditorChangedEventArgs.cs b/src/MixEmul/Events/WordValueEditorChangedEventArgs.cs index cd282aa..f6b1535 100644 --- a/src/MixEmul/Events/WordValueEditorChangedEventArgs.cs +++ b/src/MixEmul/Events/WordValueEditorChangedEventArgs.cs @@ -1,17 +1,11 @@ -using System; +using System; using MixLib.Type; namespace MixGui.Events { - public class WordEditorValueChangedEventArgs : EventArgs + public class WordEditorValueChangedEventArgs(IWord oldValue, IWord newValue) : EventArgs { - public IWord NewValue { get; private set; } - public IWord OldValue { get; private set; } - - public WordEditorValueChangedEventArgs(IWord oldValue, IWord newValue) - { - OldValue = oldValue; - NewValue = newValue; - } - } + public IWord NewValue => newValue; + public IWord OldValue => oldValue; + } } diff --git a/src/MixEmul/MixEmul.csproj b/src/MixEmul/MixEmul.csproj index 9259d82..415a65d 100644 --- a/src/MixEmul/MixEmul.csproj +++ b/src/MixEmul/MixEmul.csproj @@ -1,6 +1,6 @@  - net8.0-windows + net8.0-windows7.0 WinExe MixGui.MixForm ..\..\img\MixFormIcon.ico diff --git a/src/MixEmul/MixForm.cs b/src/MixEmul/MixForm.cs index fa20427..30059af 100644 --- a/src/MixEmul/MixForm.cs +++ b/src/MixEmul/MixForm.cs @@ -572,12 +572,12 @@ private void InitializeComponent() // mMainMenuStrip // this.mainMenuStrip.Dock = DockStyle.None; - this.mainMenuStrip.Items.AddRange(new ToolStripItem[] { + this.mainMenuStrip.Items.AddRange([ this.fileToolStripMenuItem, this.viewToolStripMenuItem, this.actionsToolStripMenuItem, toolsToolStripMenuItem, - this.helpToolStripMenuItem}); + this.helpToolStripMenuItem]); this.mainMenuStrip.Location = new Point(0, 0); this.mainMenuStrip.Name = "mMainMenuStrip"; this.mainMenuStrip.Size = new Size(804, 24); @@ -586,10 +586,10 @@ private void InitializeComponent() // // mFileToolStripMenuItem // - this.fileToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { + this.fileToolStripMenuItem.DropDownItems.AddRange([ this.openProgramToolStripMenuItem, fileMenuToolStripSeparator, - this.exitToolStripMenuItem}); + this.exitToolStripMenuItem]); this.fileToolStripMenuItem.Name = "mFileToolStripMenuItem"; this.fileToolStripMenuItem.Size = new Size(37, 20); this.fileToolStripMenuItem.Text = "&File"; @@ -612,14 +612,14 @@ private void InitializeComponent() // // mViewToolStripMenuItem // - this.viewToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { + this.viewToolStripMenuItem.DropDownItems.AddRange([ this.teletypeToolStripMenuItem, this.deviceEditorToolStripMenuItem, toolStripSeparator10, this.showSourceInlineMenuItem, toolStripSeparator8, this.findMenuItem, - this.findNextMenuItem}); + this.findNextMenuItem]); this.viewToolStripMenuItem.Name = "mViewToolStripMenuItem"; this.viewToolStripMenuItem.Size = new Size(44, 20); this.viewToolStripMenuItem.Text = "&View"; @@ -670,7 +670,7 @@ private void InitializeComponent() // // mActionsToolStripMenuItem // - this.actionsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { + this.actionsToolStripMenuItem.DropDownItems.AddRange([ this.tickToolStripMenuItem, this.stepToolStripMenuItem, this.runToolStripMenuItem, @@ -679,7 +679,7 @@ private void InitializeComponent() this.detachToolStripMenuItem, toolStripSeparator2, this.clearBreakpointsToolStripMenuItem, - this.resetToolStripMenuItem}); + this.resetToolStripMenuItem]); this.actionsToolStripMenuItem.Name = "mActionsToolStripMenuItem"; this.actionsToolStripMenuItem.Size = new Size(59, 20); this.actionsToolStripMenuItem.Text = "&Actions"; @@ -748,12 +748,12 @@ private void InitializeComponent() // // mToolsToolStripMenuItem // - toolsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { + toolsToolStripMenuItem.DropDownItems.AddRange([ this.preferencesToolStripMenuItem, toolStripSeparator9, this.profilingEnabledMenuItem, this.profilingShowTickCountsMenuItem, - this.profilingResetCountsMenuItem}); + this.profilingResetCountsMenuItem]); toolsToolStripMenuItem.Name = "mToolsToolStripMenuItem"; toolsToolStripMenuItem.Size = new Size(48, 20); toolsToolStripMenuItem.Text = "&Tools"; @@ -785,8 +785,8 @@ private void InitializeComponent() // // mHelpToolStripMenuItem // - this.helpToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { - this.aboutToolStripMenuItem}); + this.helpToolStripMenuItem.DropDownItems.AddRange([ + this.aboutToolStripMenuItem]); this.helpToolStripMenuItem.Name = "mHelpToolStripMenuItem"; this.helpToolStripMenuItem.Size = new Size(44, 20); this.helpToolStripMenuItem.Text = "&Help"; @@ -827,11 +827,11 @@ private void InitializeComponent() // mStatusStrip // this.statusStrip.Dock = DockStyle.None; - this.statusStrip.Items.AddRange(new ToolStripItem[] { + this.statusStrip.Items.AddRange([ this.modeToolStripStatusLabel, this.modeCycleButton, this.statusToolStripStatusLabel, - this.toolStripStatusLabel}); + this.toolStripStatusLabel]); this.statusStrip.Location = new Point(0, 0); this.statusStrip.Name = "mStatusStrip"; this.statusStrip.Size = new Size(804, 22); @@ -970,7 +970,7 @@ private void InitializeComponent() this.registersEditor.Location = new Point(8, 16); this.registersEditor.Name = "mRegistersEditor"; this.registersEditor.ReadOnly = false; - registers1.CompareIndicator = MixLib.Registers.CompValues.Equal; + registers1.CompareIndicator = Registers.CompValues.Equal; registers1.OverflowIndicator = false; this.registersEditor.Registers = registers1; this.registersEditor.Size = new Size(218, 214); @@ -1068,9 +1068,9 @@ private void InitializeComponent() // mControlToolStrip // this.controlToolStrip.Dock = DockStyle.None; - this.controlToolStrip.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden; - this.controlToolStrip.Items.AddRange(new ToolStripItem[] - { + this.controlToolStrip.GripStyle = ToolStripGripStyle.Hidden; + this.controlToolStrip.Items.AddRange( + [ this.pcToolStripLabel, this.showPCToolStripButton, toolStripSeparator3, @@ -1089,7 +1089,7 @@ private void InitializeComponent() this.resetToolStripButton, toolStripSeparator7, this.teletypeToolStripButton - }); + ]); this.controlToolStrip.Location = new Point(3, 24); this.controlToolStrip.Name = "mControlToolStrip"; diff --git a/src/MixEmul/MixForm.handlers.cs b/src/MixEmul/MixForm.handlers.cs index 394b350..85fb214 100644 --- a/src/MixEmul/MixForm.handlers.cs +++ b/src/MixEmul/MixForm.handlers.cs @@ -78,8 +78,7 @@ private void DeviceEditor_VisibleChanged(object sender, EventArgs e) private void AboutMenuItem_Click(object sender, EventArgs e) { - if (this.aboutForm == null) - this.aboutForm = new AboutForm(); + this.aboutForm ??= new AboutForm(); var teletypeWasOnTop = DisableTeletypeOnTop(); @@ -167,15 +166,12 @@ private void OpenProgramMenuItem_Click(object sender, EventArgs e) { var teletypeWasOnTop = DisableTeletypeOnTop(); - if (this.openProgramFileDialog == null) + this.openProgramFileDialog ??= new OpenFileDialog { - this.openProgramFileDialog = new OpenFileDialog - { - AddExtension = false, - Filter = "MIXAL program (*.mixal)|*.mixal|All files (*.*)|*.*", - Title = "Select program to open" - }; - } + AddExtension = false, + Filter = "MIXAL program (*.mixal)|*.mixal|All files (*.*)|*.*", + Title = "Select program to open" + }; if (this.openProgramFileDialog.ShowDialog(this) == DialogResult.OK) { @@ -196,8 +192,7 @@ private void OpenProgramMenuItem_Click(object sender, EventArgs e) private void PreferencesMenuItem_Click(object sender, EventArgs e) { - if (this.preferencesForm == null) - this.preferencesForm = new PreferencesForm(this.configuration, this.mix.Devices, this.defaultDirectory); + this.preferencesForm ??= new PreferencesForm(this.configuration, this.mix.Devices, this.defaultDirectory); var teletypeWasOnTop = DisableTeletypeOnTop(); @@ -371,8 +366,7 @@ private void MemoryTabControl_SelectedIndexChanged(object sender, EventArgs e) private void FindMenuItem_Click(object sender, EventArgs e) { - if (this.searchDialog == null) - this.searchDialog = new SearchDialog(); + this.searchDialog ??= new SearchDialog(); if (this.searchDialog.ShowDialog(this) == DialogResult.OK) { diff --git a/src/MixEmul/Settings/Configuration.cs b/src/MixEmul/Settings/Configuration.cs index f1bd617..6cb2900 100644 --- a/src/MixEmul/Settings/Configuration.cs +++ b/src/MixEmul/Settings/Configuration.cs @@ -57,14 +57,9 @@ public Configuration() private void FillEmptyMembers() { - if (Colors == null) - Colors = new Dictionary(); - - if (TickCounts == null) - TickCounts = new Dictionary(); - - if (DeviceFilePaths == null) - DeviceFilePaths = new Dictionary(); + Colors ??= []; + TickCounts ??= []; + DeviceFilePaths ??= []; } public static JsonSerializerOptions JsonSerializerOptions @@ -96,8 +91,7 @@ public static Configuration Load(string directory) catch (Exception) {} - if (configuration == null) - configuration = new(); + configuration ??= new(); configuration.FillEmptyMembers(); diff --git a/src/MixEmul/Settings/GuiSettings.cs b/src/MixEmul/Settings/GuiSettings.cs index 29e2c22..acb15ed 100644 --- a/src/MixEmul/Settings/GuiSettings.cs +++ b/src/MixEmul/Settings/GuiSettings.cs @@ -69,7 +69,7 @@ static GuiSettings() { TeletypeOutputBackground, Color.Black } }; - Colors = new Dictionary(); + Colors = []; defaultFonts = new Dictionary { { FixedWidth, new Font("Courier New", 9f, FontStyle.Regular, GraphicsUnit.Point, 0) } @@ -82,24 +82,24 @@ static GuiSettings() public static Color GetColor(string name) { - if (Colors.ContainsKey(name)) - return Colors[name]; + if (Colors.TryGetValue(name, out var value)) + return value; return GetDefaultColor(name); } public static Color GetDefaultColor(string name) { - if (defaultColors.ContainsKey(name)) - return defaultColors[name]; + if (defaultColors.TryGetValue(name, out var value)) + return value; return SystemColors.WindowText; } public static Font GetFont(string name) { - if (defaultFonts.ContainsKey(name)) - return defaultFonts[name]; + if (defaultFonts.TryGetValue(name, out var value)) + return value; var enumerator = ((IEnumerable)defaultFonts).GetEnumerator(); enumerator.MoveNext(); diff --git a/src/MixEmul/Utils/CardDeckExporter.cs b/src/MixEmul/Utils/CardDeckExporter.cs index 632dc05..6cab1b8 100644 --- a/src/MixEmul/Utils/CardDeckExporter.cs +++ b/src/MixEmul/Utils/CardDeckExporter.cs @@ -10,11 +10,11 @@ namespace MixGui.Utils public static class CardDeckExporter { public static readonly string[] DefaultLoaderCards = - { + [ " O O6 A O4 2 O6 C O4 BK 2DO6 BI G O4 3D-H M BB B U 3DEH A F F CF 0 E B LU", " 3DIH M BB B EJ CA. 2DEU B EH K BA B EU 5A-H M BB C U 4AEH 5AEN E CLU ABG", " 2DEH K BB Q B. E 9" - }; + ]; private static string[] loaderCards; @@ -129,7 +129,7 @@ private static string GetAddressText(int address) { address = -address; var addressText = address.ToString("0000"); - return addressText.Substring(0, 3) + GetNegativeDigit(addressText[3]); + return addressText[..3] + GetNegativeDigit(addressText[3]); } return address.ToString("0000"); @@ -153,7 +153,7 @@ private static string GetInformationLine(int firstWordLocation, List else { - lineBuilder.Append(numberText.Substring(0, 9)); + lineBuilder.Append(numberText[..9]); lineBuilder.Append(GetNegativeDigit(numberText[9])); } } diff --git a/src/MixLib/Device/CardReaderDevice.cs b/src/MixLib/Device/CardReaderDevice.cs index 7740393..20ac104 100644 --- a/src/MixLib/Device/CardReaderDevice.cs +++ b/src/MixLib/Device/CardReaderDevice.cs @@ -59,10 +59,8 @@ public override string StatusDescription public override StreamStep.Instance CreateStreamInstance(StreamStatus streamStatus) => new Instance(streamStatus); - private new class Instance : StreamStep.Instance + private new class Instance(StreamStatus streamStatus) : StreamStep.Instance(streamStatus) { - public Instance(StreamStatus streamStatus) : base(streamStatus) { } - public override bool Tick() { try diff --git a/src/MixLib/Device/CardWriterDevice.cs b/src/MixLib/Device/CardWriterDevice.cs index 344e57d..c017ec7 100644 --- a/src/MixLib/Device/CardWriterDevice.cs +++ b/src/MixLib/Device/CardWriterDevice.cs @@ -60,10 +60,8 @@ public override StreamStep.Instance CreateStreamInstance(StreamStatus streamStat public override string StatusDescription => OpeningDescription; - private new class Instance : StreamStep.Instance + private new class Instance(StreamStatus streamStatus) : StreamStep.Instance(streamStatus) { - public Instance(StreamStatus streamStatus) : base(streamStatus) { } - public override bool Tick() { try diff --git a/src/MixLib/Device/DiskDevice.cs b/src/MixLib/Device/DiskDevice.cs index 4ffa397..ba9e973 100644 --- a/src/MixLib/Device/DiskDevice.cs +++ b/src/MixLib/Device/DiskDevice.cs @@ -103,10 +103,8 @@ public override string StatusDescription public override StreamStep.Instance CreateStreamInstance(StreamStatus streamStatus) => new Instance(streamStatus); - private new class Instance : StreamStep.Instance + private new class Instance(StreamStatus streamStatus) : StreamStep.Instance(streamStatus) { - public Instance(StreamStatus streamStatus) : base(streamStatus) { } - public override bool Tick() { try @@ -134,13 +132,11 @@ private class SeekStep : StreamStep public override StreamStep.Instance CreateStreamInstance(StreamStatus streamStatus) => new Instance(streamStatus); - private new class Instance : StreamStep.Instance + private new class Instance(StreamStatus streamStatus) : StreamStep.Instance(streamStatus) { - private long ticksLeft; + private long ticksLeft = Unset; private const long Unset = long.MinValue; - public Instance(StreamStatus streamStatus) : base(streamStatus) => this.ticksLeft = Unset; - public override bool Tick() { var desiredPosition = CalculateBytePosition(Operands.Sector); diff --git a/src/MixLib/Device/InOutputOperands.cs b/src/MixLib/Device/InOutputOperands.cs index c7dc49f..863946f 100644 --- a/src/MixLib/Device/InOutputOperands.cs +++ b/src/MixLib/Device/InOutputOperands.cs @@ -1,23 +1,15 @@ -using MixLib.Interrupts; +using MixLib.Interrupts; using MixLib.Type; namespace MixLib.Device { - public class InOutputOperands - { - public IMemory Memory { get; private set; } - public int MValue { get; private set; } - public int Sector { get; private set; } - public InterruptQueueCallback InterruptQueueCallback { get; private set; } + public class InOutputOperands(IMemory memory, int memAddress, int sector, InterruptQueueCallback callback) + { + public IMemory Memory => memory; + public int MValue => memAddress; + public int Sector => sector; + public InterruptQueueCallback InterruptQueueCallback => callback; public InOutputOperands(IMemory memory, int memAddress, int sector) : this(memory, memAddress, sector, null) { } - - public InOutputOperands(IMemory memory, int memAddress, int sector, InterruptQueueCallback callback) - { - Memory = memory; - MValue = memAddress; - Sector = sector; - InterruptQueueCallback = callback; - } - } + } } diff --git a/src/MixLib/Device/MixDevice.cs b/src/MixLib/Device/MixDevice.cs index af7d92d..5f599fa 100644 --- a/src/MixLib/Device/MixDevice.cs +++ b/src/MixLib/Device/MixDevice.cs @@ -6,8 +6,8 @@ namespace MixLib.Device { - public abstract class MixDevice - { + public abstract class MixDevice(int id) + { private const string IdleDescription = "Idle"; private const string ReadingDescription = "Reading from memory"; private const string WritingDescription = "Writing to memory"; @@ -15,11 +15,11 @@ public abstract class MixDevice private InOutputOperands currentOperands; private DeviceStep.Instance currentStepInstance; - protected DeviceStep CurrentStep { get; private set; } - protected DeviceStep FirstInputDeviceStep { get; set; } + protected DeviceStep CurrentStep { get; private set; } = null; + protected DeviceStep FirstInputDeviceStep { get; set; } protected DeviceStep FirstIocDeviceStep { get; set; } protected DeviceStep FirstOutputDeviceStep { get; set; } - public int Id { get; private set; } + public int Id => id; public abstract int RecordWordCount { get; } public abstract string ShortName { get; } public abstract bool SupportsInput { get; } @@ -28,13 +28,7 @@ public abstract class MixDevice public event ReportingEventHandler ReportingEvent; - protected MixDevice(int id) - { - Id = id; - CurrentStep = null; - } - - public bool Busy + public bool Busy => CurrentStep != null; public string StatusDescription @@ -124,18 +118,13 @@ public void Tick() public abstract void UpdateSettings(); - protected class ReadFromMemoryStep : TickingStep + protected class ReadFromMemoryStep(bool includeSign, int recordWordCount) : TickingStep(recordWordCount) { - private readonly bool mIncludeSign; - - public ReadFromMemoryStep(bool includeSign, int recordWordCount) : base(recordWordCount) - => mIncludeSign = includeSign; - public override string StatusDescription => ReadingDescription; protected override TickingStep.Instance CreateTickingInstance() - => new Instance(TickCount, mIncludeSign); + => new Instance(TickCount, includeSign); private new class Instance : TickingStep.Instance { @@ -177,15 +166,11 @@ protected override void ProcessTick() } } - protected class WriteToMemoryStep : TickingStep + protected class WriteToMemoryStep(bool includeSign, int recordWordCount) : TickingStep(recordWordCount) { - private readonly bool mIncludeSign; - - public WriteToMemoryStep(bool includeSign, int recordWordCount) : base(recordWordCount) => mIncludeSign = includeSign; - - public override string StatusDescription => WritingDescription; + public override string StatusDescription => WritingDescription; - protected override TickingStep.Instance CreateTickingInstance() => new Instance(TickCount, mIncludeSign); + protected override TickingStep.Instance CreateTickingInstance() => new Instance(TickCount, includeSign); private new class Instance : TickingStep.Instance { diff --git a/src/MixLib/Device/PaperTapeDevice.cs b/src/MixLib/Device/PaperTapeDevice.cs index a4fb0f9..d9a501e 100644 --- a/src/MixLib/Device/PaperTapeDevice.cs +++ b/src/MixLib/Device/PaperTapeDevice.cs @@ -66,10 +66,8 @@ private class OpenStreamStep : StreamStep public override StreamStep.Instance CreateStreamInstance(StreamStatus streamStatus) => new Instance(streamStatus); - private new class Instance : StreamStep.Instance + private new class Instance(StreamStatus streamStatus) : StreamStep.Instance(streamStatus) { - public Instance(StreamStatus streamStatus) : base(streamStatus) { } - public override bool Tick() { try @@ -94,21 +92,18 @@ public override string StatusDescription public override StreamStep.Instance CreateStreamInstance(StreamStatus streamStatus) => new Instance(streamStatus); - private new class Instance : StreamStep.Instance + private new class Instance(StreamStatus streamStatus) : StreamStep.Instance(streamStatus) { - private long mTicksLeft; + private long ticksLeft = Unset; private const long Unset = long.MinValue; - public Instance(StreamStatus streamStatus) : base(streamStatus) - => mTicksLeft = Unset; - public override bool Tick() { - if (mTicksLeft == Unset) - mTicksLeft = ((StreamStatus.Position / (MyRecordWordCount * FullWord.ByteCount + Environment.NewLine.Length)) + 1L) * DeviceSettings.GetTickCount("PaperTapeRecordWind"); + if (this.ticksLeft == Unset) + this.ticksLeft = ((StreamStatus.Position / (MyRecordWordCount * FullWord.ByteCount + Environment.NewLine.Length)) + 1L) * DeviceSettings.GetTickCount("PaperTapeRecordWind"); - mTicksLeft -= 1L; - if (mTicksLeft > 0L) + this.ticksLeft -= 1L; + if (this.ticksLeft > 0L) return false; StreamStatus.Position = 0L; diff --git a/src/MixLib/Device/PrinterDevice.cs b/src/MixLib/Device/PrinterDevice.cs index 07aaea5..58cacdc 100644 --- a/src/MixLib/Device/PrinterDevice.cs +++ b/src/MixLib/Device/PrinterDevice.cs @@ -75,10 +75,8 @@ public override string StatusDescription public override StreamStep.Instance CreateStreamInstance(StreamStatus streamStatus) => new Instance(streamStatus); - private new class Instance : StreamStep.Instance + private new class Instance(StreamStatus streamStatus) : StreamStep.Instance(streamStatus) { - public Instance(StreamStatus streamStatus) : base(streamStatus) { } - public override bool Tick() { try @@ -106,10 +104,8 @@ private class PageForwardStep : StreamStep public override StreamStep.Instance CreateStreamInstance(StreamStatus streamStatus) => new Instance(streamStatus); - private new class Instance : StreamStep.Instance + private new class Instance(StreamStatus streamStatus) : StreamStep.Instance(streamStatus) { - public Instance(StreamStatus streamStatus) : base(streamStatus) { } - public override bool Tick() { if (StreamStatus.Stream == null) diff --git a/src/MixLib/Device/Settings/DeviceSettings.cs b/src/MixLib/Device/Settings/DeviceSettings.cs index 74f33df..258d263 100644 --- a/src/MixLib/Device/Settings/DeviceSettings.cs +++ b/src/MixLib/Device/Settings/DeviceSettings.cs @@ -41,7 +41,7 @@ static DeviceSettings() { TeletypeInitialization, 25 } }; - TickCounts = new Dictionary(); + TickCounts = []; deviceReloadInterval = UnsetDeviceReloadInterval; } @@ -53,7 +53,7 @@ public static int GetDefaultTickCount(string name) => IsKnownTickCount(name) ? defaultTickCounts[name] : DefaultDefaultTickCount; public static int GetTickCount(string name) - => TickCounts.ContainsKey(name) ? TickCounts[name] : GetDefaultTickCount(name); + => TickCounts.TryGetValue(name, out var value) ? value : GetDefaultTickCount(name); public static string DefaultDeviceFilesDirectory { diff --git a/src/MixLib/Device/Step/BinaryReadStep.cs b/src/MixLib/Device/Step/BinaryReadStep.cs index 3e73e83..27df067 100644 --- a/src/MixLib/Device/Step/BinaryReadStep.cs +++ b/src/MixLib/Device/Step/BinaryReadStep.cs @@ -6,15 +6,12 @@ namespace MixLib.Device.Step { - public class BinaryReadStep : StreamStep + public class BinaryReadStep(int recordWordCount) : StreamStep { - private readonly int recordWordCount; + private readonly int recordWordCount = recordWordCount; private const string MyStatusDescription = "Reading binary data"; - public BinaryReadStep(int recordWordCount) - => this.recordWordCount = recordWordCount; - public override string StatusDescription => MyStatusDescription; @@ -60,13 +57,9 @@ public static IFullWord[] ReadWords(Stream stream, int wordCount) return readWords; } - private new class Instance : StreamStep.Instance + private new class Instance(StreamStatus streamStatus, int recordWordCount) : StreamStep.Instance(streamStatus) { private MixByte[] mReadBytes; - private readonly int mRecordWordCount; - - public Instance(StreamStatus streamStatus, int recordWordCount) : base(streamStatus) - => mRecordWordCount = recordWordCount; public override object OutputForNextStep => mReadBytes; @@ -78,13 +71,13 @@ public override bool Tick() try { - mReadBytes = ReadBytes(StreamStatus.Stream, mRecordWordCount); + mReadBytes = ReadBytes(StreamStatus.Stream, recordWordCount); StreamStatus.UpdatePosition(); } catch (Exception exception) { OnReportingEvent(new ReportingEventArgs(Severity.Error, "exception while reading file " + StreamStatus.FileName + ": " + exception.Message)); - mReadBytes = Array.Empty(); + mReadBytes = []; } return true; diff --git a/src/MixLib/Device/Step/BinaryWriteStep.cs b/src/MixLib/Device/Step/BinaryWriteStep.cs index 1f2b005..56f0ba8 100644 --- a/src/MixLib/Device/Step/BinaryWriteStep.cs +++ b/src/MixLib/Device/Step/BinaryWriteStep.cs @@ -6,19 +6,15 @@ namespace MixLib.Device.Step { - public class BinaryWriteStep : StreamStep + public class BinaryWriteStep(int recordWordCount) : StreamStep { - private readonly int recordWordCount; private const string MyStatusDescription = "Writing binary data"; - public BinaryWriteStep(int recordWordCount) - => this.recordWordCount = recordWordCount; - public override string StatusDescription => MyStatusDescription; public override StreamStep.Instance CreateStreamInstance(StreamStatus streamStatus) - => new Instance(streamStatus, this.recordWordCount); + => new Instance(streamStatus, recordWordCount); public static void WriteWords(Stream stream, int wordCount, IFullWord[] writeWords) { @@ -48,14 +44,10 @@ public static void WriteBytes(Stream stream, int wordCount, MixByte[] writeBytes stream.Flush(); } - private new class Instance : StreamStep.Instance + private new class Instance(StreamStatus streamStatus, int recordWordCount) : StreamStep.Instance(streamStatus) { - private readonly int recordWordCount; private MixByte[] writeBytes; - public Instance(StreamStatus streamStatus, int recordWordCount) : base(streamStatus) - => this.recordWordCount = recordWordCount; - public override bool Tick() { if (StreamStatus.Stream == null || this.writeBytes == null) @@ -63,7 +55,7 @@ public override bool Tick() try { - WriteBytes(StreamStatus.Stream, this.recordWordCount, this.writeBytes); + WriteBytes(StreamStatus.Stream, recordWordCount, this.writeBytes); StreamStatus.UpdatePosition(); } catch (Exception exception) diff --git a/src/MixLib/Device/Step/CloseStreamStep.cs b/src/MixLib/Device/Step/CloseStreamStep.cs index d3e2cde..95fe585 100644 --- a/src/MixLib/Device/Step/CloseStreamStep.cs +++ b/src/MixLib/Device/Step/CloseStreamStep.cs @@ -10,10 +10,8 @@ public override string StatusDescription public override StreamStep.Instance CreateStreamInstance(StreamStatus streamStatus) => new Instance(streamStatus); - private new class Instance : StreamStep.Instance + private new class Instance(StreamStatus streamStatus) : StreamStep.Instance(streamStatus) { - public Instance(StreamStatus streamStatus) : base(streamStatus) { } - public override bool Tick() { StreamStatus.CloseStream(); diff --git a/src/MixLib/Device/Step/NoOpStep.cs b/src/MixLib/Device/Step/NoOpStep.cs index 3a74c64..ada3fe8 100644 --- a/src/MixLib/Device/Step/NoOpStep.cs +++ b/src/MixLib/Device/Step/NoOpStep.cs @@ -1,22 +1,15 @@ namespace MixLib.Device.Step { - public class NoOpStep : TickingStep + public class NoOpStep(int tickCount, string statusDescription) : TickingStep(tickCount) { - private readonly string statusDescription; - - public NoOpStep(int tickCount, string statusDescription) : base(tickCount) - => this.statusDescription = statusDescription; - public override string StatusDescription - => this.statusDescription; + => statusDescription; protected override TickingStep.Instance CreateTickingInstance() => new Instance(TickCount); - protected new class Instance : TickingStep.Instance + protected new class Instance(int tickCount) : TickingStep.Instance(tickCount) { - public Instance(int tickCount) : base(tickCount) { } - protected override void ProcessTick() { } } } diff --git a/src/MixLib/Device/Step/StreamStep.cs b/src/MixLib/Device/Step/StreamStep.cs index 178536b..6fc8897 100644 --- a/src/MixLib/Device/Step/StreamStep.cs +++ b/src/MixLib/Device/Step/StreamStep.cs @@ -9,12 +9,9 @@ public override DeviceStep.Instance CreateInstance() public abstract Instance CreateStreamInstance(StreamStatus streamStatus); - public new abstract class Instance : DeviceStep.Instance + public new abstract class Instance(StreamStatus streamStatus) : DeviceStep.Instance { - protected StreamStatus StreamStatus { get; private set; } - - protected Instance(StreamStatus streamStatus) - => StreamStatus = streamStatus; + protected StreamStatus StreamStatus { get; private set; } = streamStatus; } } } diff --git a/src/MixLib/Device/Step/TextReadStep.cs b/src/MixLib/Device/Step/TextReadStep.cs index 9bd2d2c..a39f1ac 100644 --- a/src/MixLib/Device/Step/TextReadStep.cs +++ b/src/MixLib/Device/Step/TextReadStep.cs @@ -8,19 +8,15 @@ namespace MixLib.Device.Step { - public class TextReadStep : StreamStep + public class TextReadStep(int recordWordCount) : StreamStep { - private readonly int recordWordCount; private const string MyStatusDescription = "Reading textual data"; - public TextReadStep(int recordWordCount) - => this.recordWordCount = recordWordCount; - public override string StatusDescription => MyStatusDescription; public override StreamStep.Instance CreateStreamInstance(StreamStatus streamStatus) - => new Instance(streamStatus, this.recordWordCount); + => new Instance(streamStatus, recordWordCount); public static List ReadBytes(Stream stream, int bytesPerRecord) { @@ -50,13 +46,9 @@ private static MixByte[] ProcessReadText(string readText, int resultByteCount) return readBytes; } - private new class Instance : StreamStep.Instance + private new class Instance(StreamStatus streamStatus, int recordWordCount) : StreamStep.Instance(streamStatus) { private MixByte[] readBytes; - private readonly int recordWordCount; - - public Instance(StreamStatus streamStatus, int recordWordCount) : base(streamStatus) - => this.recordWordCount = recordWordCount; public override object OutputForNextStep => this.readBytes; @@ -79,7 +71,7 @@ public override bool Tick() OnReportingEvent(new ReportingEventArgs(Severity.Error, "exception while reading file " + StreamStatus.FileName + ": " + exception.Message)); } - this.readBytes = ProcessReadText(readText, this.recordWordCount * FullWord.ByteCount); + this.readBytes = ProcessReadText(readText, recordWordCount * FullWord.ByteCount); return true; } diff --git a/src/MixLib/Device/Step/TextWriteStep.cs b/src/MixLib/Device/Step/TextWriteStep.cs index f6547b9..9a1b32b 100644 --- a/src/MixLib/Device/Step/TextWriteStep.cs +++ b/src/MixLib/Device/Step/TextWriteStep.cs @@ -8,26 +8,22 @@ namespace MixLib.Device.Step { - public class TextWriteStep : StreamStep + public class TextWriteStep(int recordWordCount) : StreamStep { - private readonly int recordWordCount; private const string MyStatusDescription = "Writing textual data"; - public TextWriteStep(int recordWordCount) - => this.recordWordCount = recordWordCount; - public override string StatusDescription => MyStatusDescription; public override StreamStep.Instance CreateStreamInstance(StreamStatus streamStatus) - => new Instance(streamStatus, this.recordWordCount); + => new Instance(streamStatus, recordWordCount); public static void WriteBytes(Stream stream, int bytesPerRecord, List bytes) { var writer = new StreamWriter(stream, Encoding.ASCII); foreach (IMixByteCollection collection in bytes) - writer.WriteLine(CreateStringFromBytes(collection.ToArray(), bytesPerRecord)); + writer.WriteLine(CreateStringFromBytes([.. collection], bytesPerRecord)); writer.Flush(); } @@ -47,14 +43,10 @@ private static string CreateStringFromBytes(MixByte[] bytes, int maxByteCount) return new String(charsToWrite).TrimEnd(' '); } - private new class Instance : StreamStep.Instance + private new class Instance(StreamStatus streamStatus, int recordWordCount) : StreamStep.Instance(streamStatus) { - private readonly int recordWordCount; private MixByte[] writeBytes; - public Instance(StreamStatus streamStatus, int recordWordCount) : base(streamStatus) - => this.recordWordCount = recordWordCount; - public override bool Tick() { if (StreamStatus.Stream == null || this.writeBytes == null) @@ -63,7 +55,7 @@ public override bool Tick() try { var writer = new StreamWriter(StreamStatus.Stream, Encoding.ASCII); - writer.WriteLine(CreateStringFromBytes(this.writeBytes, this.recordWordCount * FullWord.ByteCount)); + writer.WriteLine(CreateStringFromBytes(this.writeBytes, recordWordCount * FullWord.ByteCount)); writer.Flush(); StreamStatus.UpdatePosition(); } diff --git a/src/MixLib/Device/Step/TickingStep.cs b/src/MixLib/Device/Step/TickingStep.cs index 3b649f3..3e2f6f6 100644 --- a/src/MixLib/Device/Step/TickingStep.cs +++ b/src/MixLib/Device/Step/TickingStep.cs @@ -1,26 +1,17 @@ namespace MixLib.Device.Step { - public abstract class TickingStep : DeviceStep + public abstract class TickingStep(int tickCount) : DeviceStep { - protected int TickCount { get; private set; } + protected int TickCount => tickCount; - protected TickingStep(int tickCount) - => TickCount = tickCount; - - public sealed override DeviceStep.Instance CreateInstance() => CreateTickingInstance(); + public sealed override DeviceStep.Instance CreateInstance() => CreateTickingInstance(); protected abstract Instance CreateTickingInstance(); - protected new abstract class Instance : DeviceStep.Instance + protected new abstract class Instance(int tickCount) : DeviceStep.Instance { - protected int CurrentTick { get; private set; } - protected int TickCount { get; private set; } - - protected Instance(int tickCount) - { - TickCount = tickCount; - CurrentTick = 0; - } + protected int CurrentTick { get; private set; } = 0; + protected int TickCount => tickCount; protected abstract void ProcessTick(); diff --git a/src/MixLib/Device/TapeDevice.cs b/src/MixLib/Device/TapeDevice.cs index 5ff3381..75bda09 100644 --- a/src/MixLib/Device/TapeDevice.cs +++ b/src/MixLib/Device/TapeDevice.cs @@ -86,10 +86,8 @@ public override string StatusDescription public override StreamStep.Instance CreateStreamInstance(StreamStatus streamStatus) => new Instance(streamStatus); - private new class Instance : StreamStep.Instance + private new class Instance(StreamStatus streamStatus) : StreamStep.Instance(streamStatus) { - public Instance(StreamStatus streamStatus) : base(streamStatus) { } - public override bool Tick() { try @@ -118,14 +116,11 @@ public override string StatusDescription public override StreamStep.Instance CreateStreamInstance(StreamStatus streamStatus) => new Instance(streamStatus); - private new class Instance : StreamStep.Instance + private new class Instance(StreamStatus streamStatus) : StreamStep.Instance(streamStatus) { - private long ticksLeft; + private long ticksLeft = Unset; private const long Unset = long.MinValue; - public Instance(StreamStatus streamStatus) : base(streamStatus) - => this.ticksLeft = Unset; - public override bool Tick() { if (this.ticksLeft == Unset) diff --git a/src/MixLib/Device/TeletypeDevice.cs b/src/MixLib/Device/TeletypeDevice.cs index 8d55495..c978f1f 100644 --- a/src/MixLib/Device/TeletypeDevice.cs +++ b/src/MixLib/Device/TeletypeDevice.cs @@ -98,39 +98,31 @@ public sealed override void UpdateSettings() FirstIocDeviceStep = null; } - private class ReadLineStep : DeviceStep + private class ReadLineStep(Queue inputBuffer) : DeviceStep { - private readonly Queue inputBuffer; - - public ReadLineStep(Queue inputBuffer) - => this.inputBuffer = inputBuffer; - public override string StatusDescription => ReadingDescription; public override DeviceStep.Instance CreateInstance() - => new Instance(this.inputBuffer); + => new Instance(inputBuffer); - public new class Instance : DeviceStep.Instance + public new class Instance(Queue inputBuffer) : DeviceStep.Instance { - private readonly Queue inputBuffer; private MixByte[] readBytes; public event EventHandler InputRequired; - public Instance(Queue inputBuffer) => this.inputBuffer = inputBuffer; - public override object OutputForNextStep => this.readBytes; public override bool Tick() { - if (this.inputBuffer.Count == 0) + if (inputBuffer.Count == 0) { InputRequired(this, new EventArgs()); return false; } - string stringToRead = (this.inputBuffer.Count == 0) ? string.Empty : ((string)this.inputBuffer.Dequeue()); + string stringToRead = (inputBuffer.Count == 0) ? string.Empty : ((string)inputBuffer.Dequeue()); this.readBytes = new MixByte[FullWord.ByteCount * MyRecordWordCount]; var bytesToReadCount = Math.Min(stringToRead.Length, this.readBytes.Length); @@ -153,29 +145,20 @@ public override bool Tick() } } - private class WriteLineStep : DeviceStep + private class WriteLineStep(Queue outputBuffer) : DeviceStep { - private readonly Queue outputBuffer; - - public WriteLineStep(Queue outputBuffer) - => this.outputBuffer = outputBuffer; - public override string StatusDescription => WritingDescription; public override DeviceStep.Instance CreateInstance() - => new Instance(this.outputBuffer); + => new Instance(outputBuffer); - public new class Instance : DeviceStep.Instance + public new class Instance(Queue outputBuffer) : DeviceStep.Instance { - private readonly Queue outputBuffer; private MixByte[] writeBytes; public event EventHandler OutputAdded; - public Instance(Queue outputBuffer) - => this.outputBuffer = outputBuffer; - public override bool Tick() { if (this.writeBytes == null) @@ -197,7 +180,7 @@ public override bool Tick() index++; } - this.outputBuffer.Enqueue(new string(charsToWrite).TrimEnd(Array.Empty())); + outputBuffer.Enqueue(new string(charsToWrite).TrimEnd([])); OutputAdded(this, new EventArgs()); diff --git a/src/MixLib/Events/DeviceReportingEventArgs.cs b/src/MixLib/Events/DeviceReportingEventArgs.cs index 26850cb..4fe2990 100644 --- a/src/MixLib/Events/DeviceReportingEventArgs.cs +++ b/src/MixLib/Events/DeviceReportingEventArgs.cs @@ -3,11 +3,8 @@ namespace MixLib.Events { - public class DeviceReportingEventArgs : ReportingEventArgs + public class DeviceReportingEventArgs(MixDevice reportingDevice, Severity severity, string message) : ReportingEventArgs(severity, message) { - public MixDevice ReportingDevice { get; private set; } - - public DeviceReportingEventArgs(MixDevice reportingDevice, Severity severity, string message) : base(severity, message) - => ReportingDevice = reportingDevice; - } + public MixDevice ReportingDevice => reportingDevice; + } } diff --git a/src/MixLib/Events/ReportingEventArgs.cs b/src/MixLib/Events/ReportingEventArgs.cs index fbd89b9..6b0eb5f 100644 --- a/src/MixLib/Events/ReportingEventArgs.cs +++ b/src/MixLib/Events/ReportingEventArgs.cs @@ -1,16 +1,10 @@ -using System; +using System; namespace MixLib.Events { - public class ReportingEventArgs : EventArgs + public class ReportingEventArgs(Misc.Severity severity, string message) : EventArgs { - public string Message { get; private set; } - public MixLib.Misc.Severity Severity { get; private set; } - - public ReportingEventArgs(MixLib.Misc.Severity severity, string message) - { - Severity = severity; - Message = message; - } - } + public string Message => message; + public Misc.Severity Severity => severity; + } } diff --git a/src/MixLib/Instruction/FloatingPointInstructions.cs b/src/MixLib/Instruction/FloatingPointInstructions.cs index 06f220c..2e2c663 100644 --- a/src/MixLib/Instruction/FloatingPointInstructions.cs +++ b/src/MixLib/Instruction/FloatingPointInstructions.cs @@ -15,7 +15,7 @@ public static class FloatingPointInstructions public const string FCMP_Mnemonic = "FCMP"; private static ExecutionStatus executionStatus; - private static readonly int[] prenormOpcodes = { FADD_Opcode, FSUB_Opcode, FMUL_Opcode, FDIV_Opcode }; + private static readonly int[] prenormOpcodes = [FADD_Opcode, FSUB_Opcode, FMUL_Opcode, FDIV_Opcode]; public static bool DoFloatingPoint(ModuleBase module, MixInstruction.Instance instance) { @@ -35,8 +35,7 @@ public static bool DoFloatingPoint(ModuleBase module, MixInstruction.Instance in if (executionStatus != null && executionStatus.ProgramCounter != module.ProgramCounter) executionStatus = null; - if (executionStatus == null) - executionStatus = new ExecutionStatus(module.Mode, module.ProgramCounter, instance.Instruction.Mnemonic); + executionStatus ??= new ExecutionStatus(module.Mode, module.ProgramCounter, instance.Instruction.Mnemonic); if (executionStatus.CurrentStep == ExecutionStatus.Step.Initialize && !InitializeInstruction(module, instance, floatingPointModule)) return false; @@ -182,24 +181,15 @@ private static bool InitializeInstruction(ModuleBase module, MixInstruction.Inst return true; } - private class ExecutionStatus + private class ExecutionStatus(ModuleBase.RunMode mode, int programCounter, string mnemonic) { - public ModuleBase.RunMode Mode { get; private set; } - public string Mnemonic { get; private set; } - public int ProgramCounter { get; private set; } - public Step CurrentStep { get; set; } + public ModuleBase.RunMode Mode => mode; + public string Mnemonic => mnemonic; + public int ProgramCounter => programCounter; + public Step CurrentStep { get; set; } = Step.Initialize; public IFullWord ParameterValue { get; set; } public IFullWord RAValue { get; set; } - public bool OverflowDetected { get; set; } - - public ExecutionStatus(ModuleBase.RunMode mode, int programCounter, string mnemonic) - { - Mode = mode; - ProgramCounter = programCounter; - Mnemonic = mnemonic; - CurrentStep = Step.Initialize; - OverflowDetected = false; - } + public bool OverflowDetected { get; set; } = false; public enum Step { diff --git a/src/MixLib/Instruction/IOInstructions.cs b/src/MixLib/Instruction/IOInstructions.cs index a1a07a6..7137a2f 100644 --- a/src/MixLib/Instruction/IOInstructions.cs +++ b/src/MixLib/Instruction/IOInstructions.cs @@ -64,7 +64,7 @@ public static InstanceValidationError[] InstanceValid(MixInstruction.Instance in } if (index == 1) - return new InstanceValidationError[] { errorArray[0] }; + return [errorArray[0]]; if (index == 2) return errorArray; diff --git a/src/MixLib/Instruction/InstructionBase.cs b/src/MixLib/Instruction/InstructionBase.cs index 9806d9e..a3e6b25 100644 --- a/src/MixLib/Instruction/InstructionBase.cs +++ b/src/MixLib/Instruction/InstructionBase.cs @@ -5,11 +5,8 @@ /// This class serves as the base class for all instruction types recognized within MIXAL. /// It defines the attributes common to all types, which basically is the fact that they all have a mnemonic. /// - public abstract class InstructionBase - { - public string Mnemonic { get; private set; } - - protected InstructionBase(string mnemonic) - => Mnemonic = mnemonic; - } + public abstract class InstructionBase(string mnemonic) + { + public string Mnemonic => mnemonic; + } } diff --git a/src/MixLib/Instruction/InstructionHelpers.cs b/src/MixLib/Instruction/InstructionHelpers.cs index 908a960..e47f1d0 100644 --- a/src/MixLib/Instruction/InstructionHelpers.cs +++ b/src/MixLib/Instruction/InstructionHelpers.cs @@ -10,7 +10,7 @@ public static int GetValidIndexedAddress(ModuleBase module, int addressBase, int => GetValidIndexedAddress(module, addressBase, registerIndex, true); public static InstanceValidationError[] ValidateIndex(MixInstruction.Instance instance) - => instance.Index > 6 ? new InstanceValidationError[] { new InstanceValidationError(InstanceValidationError.Sources.Index, 0, 6) } : null; + => instance.Index > 6 ? [new InstanceValidationError(InstanceValidationError.Sources.Index, 0, 6)] : null; public static int GetValidIndexedAddress(ModuleBase module, int addressBase, int registerIndex, bool reportErrors) { @@ -51,7 +51,7 @@ public static InstanceValidationError[] ValidateIndexAndFieldSpec(MixInstruction } if (index == 1) - return new InstanceValidationError[] { errorArray[0] }; + return [errorArray[0]]; if (index == 2) return errorArray; diff --git a/src/MixLib/Instruction/InstructionText.cs b/src/MixLib/Instruction/InstructionText.cs index 215950c..bb1454c 100644 --- a/src/MixLib/Instruction/InstructionText.cs +++ b/src/MixLib/Instruction/InstructionText.cs @@ -2,29 +2,24 @@ namespace MixLib.Instruction { - public class InstructionText - { - private readonly MixInstruction.Instance instance; - - public InstructionText(MixInstruction.Instance instance) - => this.instance = instance; - + public class InstructionText(MixInstruction.Instance instance) + { public string Index - => this.instance.Index != 0 ? "," + this.instance.Index : string.Empty; + => instance.Index != 0 ? "," + instance.Index : string.Empty; public string InstanceText => Mnemonic + " " + Address + Index + Field; public string Mnemonic - => this.instance.MixInstruction.Mnemonic; + => instance.MixInstruction.Mnemonic; private string FieldText { get { - FieldSpec fieldSpec = this.instance.FieldSpec; + FieldSpec fieldSpec = instance.FieldSpec; - if (this.instance.MixInstruction.MetaFieldSpec.FieldIsRange && fieldSpec.IsValid) + if (instance.MixInstruction.MetaFieldSpec.FieldIsRange && fieldSpec.IsValid) return (fieldSpec.LowBound + ":" + fieldSpec.HighBound); return fieldSpec.MixByteValue.ByteValue.ToString(); @@ -35,9 +30,9 @@ public string Address { get { - var addressText = this.instance.AddressMagnitude.ToString(); + var addressText = instance.AddressMagnitude.ToString(); - if (this.instance.AddressSign.IsNegative()) + if (instance.AddressSign.IsNegative()) addressText = '-' + addressText; return addressText; @@ -49,10 +44,10 @@ public string Field get { string str = null; - switch (this.instance.MixInstruction.MetaFieldSpec.Presence) + switch (instance.MixInstruction.MetaFieldSpec.Presence) { case MetaFieldSpec.Presences.Optional: - if (this.instance.FieldSpec != this.instance.MixInstruction.MetaFieldSpec.DefaultFieldSpec) + if (instance.FieldSpec != instance.MixInstruction.MetaFieldSpec.DefaultFieldSpec) str = FieldText; break; diff --git a/src/MixLib/Instruction/LoaderInstruction.cs b/src/MixLib/Instruction/LoaderInstruction.cs index 8420ada..5734c58 100644 --- a/src/MixLib/Instruction/LoaderInstruction.cs +++ b/src/MixLib/Instruction/LoaderInstruction.cs @@ -10,32 +10,19 @@ namespace MixLib.Instruction /// * The operation the loader instruction stands for /// * An indication if the instruction's parameter value ("address section") is alfanumeric /// - public class LoaderInstruction : InstructionBase + public class LoaderInstruction(string mnemonic, LoaderInstruction.Operations operation, bool alphanumeric) : InstructionBase(mnemonic) { - public bool Alphanumeric { get; private set; } - public Operations Operation { get; private set; } - - public LoaderInstruction(string mnemonic, Operations operation, bool alphanumeric) : base(mnemonic) - { - Operation = operation; - Alphanumeric = alphanumeric; - } + public bool Alphanumeric => alphanumeric; + public Operations Operation => operation; /// /// This class represents a specific instance of a loader instruction. /// - public class Instance : InstructionInstanceBase + public class Instance(LoaderInstruction instruction, Word.Signs sign, long magnitude) : InstructionInstanceBase { - private readonly LoaderInstruction instruction; - public FullWord Value { get; private set; } - - public Instance(LoaderInstruction instruction, Word.Signs sign, long magnitude) - { - this.instruction = instruction; - Value = new FullWord(sign, magnitude); - } + public FullWord Value { get; private set; } = new FullWord(sign, magnitude); - public override InstructionBase Instruction => this.instruction; + public override InstructionBase Instruction => instruction; } public enum Operations diff --git a/src/MixLib/Instruction/MiscInstructions.cs b/src/MixLib/Instruction/MiscInstructions.cs index 5344b08..28e7f0b 100644 --- a/src/MixLib/Instruction/MiscInstructions.cs +++ b/src/MixLib/Instruction/MiscInstructions.cs @@ -10,7 +10,7 @@ namespace MixLib.Instruction /// public static class MiscInstructions { - private static readonly SortedDictionary moveStatuses = new(); + private static readonly SortedDictionary moveStatuses = []; private const byte ZeroCharValue = 30; @@ -85,7 +85,7 @@ public static bool ConvertToNumeric(ModuleBase module, MixInstruction.Instance i public static bool ForceInterrupt(ModuleBase module, MixInstruction.Instance instance) { - if (!(module is Mix)) + if (module is not Mix) { module.ReportRuntimeError($"The {instance.Instruction.Mnemonic} instruction is only available in Mix"); return false; @@ -185,26 +185,16 @@ public static bool Move(ModuleBase module, MixInstruction.Instance instance) /// This helper class tracks the status of a running MOVE instruction. It is necessary because a MIX MOVE instruction takes /// several ticks, the exact number of ticks depending on the number of words moved. /// - private class MoveStatus - { - public int CurrentWord { get; private set; } - public WordStates CurrentWordState { get; set; } - public int FromAddress { get; private set; } - public int ProgramCounter { get; private set; } - public int ToAddress { get; private set; } - public byte WordCount { get; private set; } - - public MoveStatus(int programCounter, int fromAddress, int toAddress, byte wordCount) - { - ProgramCounter = programCounter; - FromAddress = fromAddress; - ToAddress = toAddress; - WordCount = wordCount; - CurrentWord = 0; - CurrentWordState = WordStates.BeforeMove; - } - - public void NextWord() + private class MoveStatus(int programCounter, int fromAddress, int toAddress, byte wordCount) + { + public int CurrentWord { get; private set; } = 0; + public WordStates CurrentWordState { get; set; } = WordStates.BeforeMove; + public int FromAddress => fromAddress; + public int ProgramCounter => programCounter; + public int ToAddress => toAddress; + public byte WordCount => wordCount; + + public void NextWord() => CurrentWord++; public enum WordStates diff --git a/src/MixLib/Instruction/MixInstruction.cs b/src/MixLib/Instruction/MixInstruction.cs index fdfd544..3f6a698 100644 --- a/src/MixLib/Instruction/MixInstruction.cs +++ b/src/MixLib/Instruction/MixInstruction.cs @@ -1,4 +1,4 @@ -using System; +using System; using MixLib.Modules; using MixLib.Type; @@ -111,10 +111,10 @@ public override string ToString() => new InstructionText(this).InstanceText; private static int AddressMagnitudeFromWord(IWord word) - => (int)Word.BytesToLong(Word.Signs.Positive, new MixByte[] { word[0], word[1] }); + => (int)Word.BytesToLong(Word.Signs.Positive, [word[0], word[1]]); private static int AddressValueFromWord(IWord word) - => (int)Word.BytesToLong(word.Sign, new MixByte[] { word[0], word[1] }); + => (int)Word.BytesToLong(word.Sign, [word[0], word[1]]); public bool Execute(ModuleBase module) { diff --git a/src/MixLib/Instruction/RuntimeValidationError.cs b/src/MixLib/Instruction/RuntimeValidationError.cs index 9cfd22f..d531103 100644 --- a/src/MixLib/Instruction/RuntimeValidationError.cs +++ b/src/MixLib/Instruction/RuntimeValidationError.cs @@ -2,24 +2,16 @@ namespace MixLib.Instruction { - public class RuntimeValidationError : ValidationError + public class RuntimeValidationError(int programCounter, MixInstruction.Instance instance, string message, int validLowerBound, int validUpperBound, int actualValue) : ValidationError(message, validLowerBound, validUpperBound) { - public int ActualValue { get; private set; } - public MixInstruction.Instance Instance { get; private set; } - public int ProgramCounter { get; private set; } + public int ActualValue => actualValue; + public MixInstruction.Instance Instance => instance; + public int ProgramCounter => programCounter; - public RuntimeValidationError(int programCounter, MixInstruction.Instance instance, string message) + public RuntimeValidationError(int programCounter, MixInstruction.Instance instance, string message) : this(programCounter, instance, message, int.MinValue, int.MinValue, int.MinValue) { } public RuntimeValidationError(int programCounter, MixInstruction.Instance instance, int validLowerBound, int validUpperBound, int actualValue) : this(programCounter, instance, null, validLowerBound, validUpperBound, actualValue) { } - - public RuntimeValidationError(int programCounter, MixInstruction.Instance instance, string message, int validLowerBound, int validUpperBound, int actualValue) - : base(message, validLowerBound, validUpperBound) - { - Instance = instance; - ProgramCounter = programCounter; - ActualValue = actualValue; - } - } + } } diff --git a/src/MixLib/InstructionSet.cs b/src/MixLib/InstructionSet.cs index 8ba35c9..75d79f5 100644 --- a/src/MixLib/InstructionSet.cs +++ b/src/MixLib/InstructionSet.cs @@ -8,8 +8,8 @@ namespace MixLib { public class InstructionSet { - private readonly SortedDictionary mnemonicInstructionMap = new(); - private readonly SortedDictionary> opcodeInstructionMap = new(); + private readonly SortedDictionary mnemonicInstructionMap = []; + private readonly SortedDictionary> opcodeInstructionMap = []; private static InstructionSet instance; public InstructionSet() @@ -272,8 +272,7 @@ public static InstructionSet Instance { get { - if (instance == null) - instance = new InstructionSet(); + instance ??= new InstructionSet(); return instance; } @@ -303,7 +302,7 @@ public MixInstruction GetInstruction(byte opcode, FieldSpec fieldSpec) } public MixInstruction this[string mnemonic] - => this.mnemonicInstructionMap.ContainsKey(mnemonic) ? this.mnemonicInstructionMap[mnemonic] : null; + => this.mnemonicInstructionMap.TryGetValue(mnemonic, out var value) ? value : null; public MixInstruction[] this[byte opcode] { @@ -319,7 +318,7 @@ public MixInstruction[] this[byte opcode] break; } - return list.ToArray(); + return [.. list]; } } } diff --git a/src/MixLib/LoaderInstructions.cs b/src/MixLib/LoaderInstructions.cs index 6545f60..9772c0b 100644 --- a/src/MixLib/LoaderInstructions.cs +++ b/src/MixLib/LoaderInstructions.cs @@ -5,7 +5,7 @@ namespace MixLib { public class LoaderInstructions { - private readonly SortedDictionary instructions = new(); + private readonly SortedDictionary instructions = []; public LoaderInstructions() { @@ -16,7 +16,7 @@ public LoaderInstructions() } public LoaderInstruction this[string mnemonic] - => this.instructions.ContainsKey(mnemonic) ? this.instructions[mnemonic] : null; + => this.instructions.TryGetValue(mnemonic, out var value) ? value : null; private void AddInstruction(string mnemonic, LoaderInstruction.Operations operation, bool alphanumeric) => this.instructions.Add(mnemonic, new LoaderInstruction(mnemonic, operation, alphanumeric)); diff --git a/src/MixLib/Memory.cs b/src/MixLib/Memory.cs index 359baf8..e66d5fa 100644 --- a/src/MixLib/Memory.cs +++ b/src/MixLib/Memory.cs @@ -20,7 +20,7 @@ public Memory(int minIndex, int maxIndex) { MinWordIndex = minIndex; MaxWordIndex = maxIndex; - this.words = new SortedDictionary(); + this.words = []; this.syncRoot = ((ICollection)this.words).SyncRoot; } @@ -246,8 +246,8 @@ public void ClearRealWordSourceLine(int index) { lock (this.syncRoot) { - if (this.words.ContainsKey(index)) - this.words[index].SourceLine = null; + if (this.words.TryGetValue(index, out var value)) + value.SourceLine = null; } } } diff --git a/src/MixLib/Misc/LogLine.cs b/src/MixLib/Misc/LogLine.cs index 86f0d98..b38d4d2 100644 --- a/src/MixLib/Misc/LogLine.cs +++ b/src/MixLib/Misc/LogLine.cs @@ -1,26 +1,16 @@  namespace MixLib.Misc { - public class LogLine - { + public class LogLine(string moduleName, Severity severity, int address, string title, string message) + { public const int NoAddress = -1; + public int Address => address; + public string Message => message; + public Severity Severity => severity; + public string Title => title; + public string ModuleName => moduleName; - public int Address { get; private set; } - public string Message { get; private set; } - public Misc.Severity Severity { get; private set; } - public string Title { get; private set; } - public string ModuleName { get; private set; } - - public LogLine(string moduleName, Misc.Severity severity, string title, string message) + public LogLine(string moduleName, Severity severity, string title, string message) : this(moduleName, severity, NoAddress, title, message) { } - - public LogLine(string moduleName, Misc.Severity severity, int address, string title, string message) - { - Severity = severity; - Address = address; - Title = title; - Message = message; - ModuleName = moduleName; - } - } + } } diff --git a/src/MixLib/Mix.cs b/src/MixLib/Mix.cs index 43f1d30..8395fa9 100644 --- a/src/MixLib/Mix.cs +++ b/src/MixLib/Mix.cs @@ -276,8 +276,7 @@ public void SignalInterruptExecuted() public override void ResetProfilingCounts() { this.fullMemory.ResetProfilingCounts(); - if (FloatingPointModule != null) - FloatingPointModule.ResetProfilingCounts(); + FloatingPointModule?.ResetProfilingCounts(); } public void Tick() diff --git a/src/MixLib/MixLib.csproj b/src/MixLib/MixLib.csproj index 7496bbf..4f4c0df 100644 --- a/src/MixLib/MixLib.csproj +++ b/src/MixLib/MixLib.csproj @@ -1,6 +1,6 @@  - net6.0-windows + net8.0-windows7.0 Library diff --git a/src/MixLib/Modules/FloatingPointModule.cs b/src/MixLib/Modules/FloatingPointModule.cs index b7495ea..1247375 100644 --- a/src/MixLib/Modules/FloatingPointModule.cs +++ b/src/MixLib/Modules/FloatingPointModule.cs @@ -20,7 +20,7 @@ public class FloatingPointModule : ModuleBase private readonly Mix mix; private readonly Memory fullMemory; - private readonly IMemory memory; + private readonly MemoryView memory; private readonly Registers registers; private RunStatus status; private int? accAddress; diff --git a/src/MixLib/Modules/Settings/ModuleSettings.cs b/src/MixLib/Modules/Settings/ModuleSettings.cs index 9146060..dab71b2 100644 --- a/src/MixLib/Modules/Settings/ModuleSettings.cs +++ b/src/MixLib/Modules/Settings/ModuleSettings.cs @@ -27,8 +27,8 @@ public static bool FloatingPointEnabledDefined if (!value) floatingPointEnabled = null; - else if (floatingPointEnabled == null) - floatingPointEnabled = FloatingPointEnabledDefault; + else + floatingPointEnabled ??= FloatingPointEnabledDefault; } } @@ -58,8 +58,8 @@ public static bool FloatingPointMemoryWordCountDefined if (!value) floatingPointMemoryWordCount = null; - else if (floatingPointMemoryWordCount == null) - floatingPointMemoryWordCount = FloatingPointMemoryWordCountDefault; + else + floatingPointMemoryWordCount ??= FloatingPointMemoryWordCountDefault; } } } diff --git a/src/MixLib/Type/FullWord.cs b/src/MixLib/Type/FullWord.cs index eb8a099..ffbd30d 100644 --- a/src/MixLib/Type/FullWord.cs +++ b/src/MixLib/Type/FullWord.cs @@ -9,7 +9,7 @@ public FullWord() : base(ByteCount) { } public FullWord(long value) : this() => LongValue = value; - public FullWord(Word.Signs sign, long magnitude) : this() + public FullWord(Signs sign, long magnitude) : this() { MagnitudeLongValue = magnitude; Sign = sign; diff --git a/src/MixLib/Type/IWord.cs b/src/MixLib/Type/IWord.cs index 174882a..c6ef8d5 100644 --- a/src/MixLib/Type/IWord.cs +++ b/src/MixLib/Type/IWord.cs @@ -3,7 +3,7 @@ namespace MixLib.Type { - public interface IWord : IEnumerable, IEnumerable, IMixByteCollection + public interface IWord : IEnumerable, IMixByteCollection { void InvertSign(); diff --git a/src/MixLib/Type/Register.cs b/src/MixLib/Type/Register.cs index c6bdcbc..14051f8 100644 --- a/src/MixLib/Type/Register.cs +++ b/src/MixLib/Type/Register.cs @@ -1,18 +1,13 @@ namespace MixLib.Type { - public abstract class Register : Word + public abstract class Register(int byteCount, int paddingByteCount) : Word(byteCount) { - private readonly int paddingByteCount; - - protected Register(int byteCount, int paddingByteCount) : base(byteCount) - => this.paddingByteCount = paddingByteCount; - public int ByteCountWithPadding - => this.paddingByteCount + ByteCount; + => paddingByteCount + ByteCount; public MixByte GetByteWithPadding(int index) - => index < this.paddingByteCount ? 0 : base[index - this.paddingByteCount]; + => index < paddingByteCount ? 0 : base[index - paddingByteCount]; public FullWord FullWordValue { @@ -20,11 +15,11 @@ public FullWord FullWordValue { var word = new FullWord(); - for (int i = 0; (i < this.paddingByteCount) && (i < FullWord.ByteCount); i++) + for (int i = 0; (i < paddingByteCount) && (i < FullWord.ByteCount); i++) word[i] = 0; for (int i = 0; (i < ByteCount) && (i < FullWord.ByteCount); i++) - word[this.paddingByteCount + i] = base[i]; + word[paddingByteCount + i] = base[i]; word.Sign = Sign; diff --git a/src/MixLib/Type/SymbolBase.cs b/src/MixLib/Type/SymbolBase.cs index 559d8dd..9831577 100644 --- a/src/MixLib/Type/SymbolBase.cs +++ b/src/MixLib/Type/SymbolBase.cs @@ -1,12 +1,9 @@ namespace MixLib.Type { - public abstract class SymbolBase : IValue + public abstract class SymbolBase(string name) : IValue { - public string Name { get; private set; } - - protected SymbolBase(string name) - => Name = name; + public string Name => name; public virtual long MemoryWordValue => 0L; diff --git a/src/MixLib/Type/SymbolCollection.cs b/src/MixLib/Type/SymbolCollection.cs index 560e865..cbae497 100644 --- a/src/MixLib/Type/SymbolCollection.cs +++ b/src/MixLib/Type/SymbolCollection.cs @@ -6,13 +6,13 @@ namespace MixLib.Type { public sealed class SymbolCollection : IEnumerable, IEnumerable { - private readonly SortedList list = new(); + private readonly SortedList list = []; public int Count => this.list.Count; public SymbolBase this[string name] - => this.list.ContainsKey(name) ? this.list[name] : null; + => this.list.TryGetValue(name, out var value) ? value : null; public bool Contains(SymbolBase value) => Contains(value.Name); diff --git a/src/MixLib/Type/VirtualMemoryFullWord.cs b/src/MixLib/Type/VirtualMemoryFullWord.cs index 51776c5..277e152 100644 --- a/src/MixLib/Type/VirtualMemoryFullWord.cs +++ b/src/MixLib/Type/VirtualMemoryFullWord.cs @@ -6,7 +6,7 @@ namespace MixLib.Type { - public class VirtualMemoryFullWord : IMemoryFullWord + public class VirtualMemoryFullWord(IMemory memory, int index) : IMemoryFullWord { private static readonly string defaultCharString; private static readonly string defaultNonCharString; @@ -15,10 +15,10 @@ public class VirtualMemoryFullWord : IMemoryFullWord private static readonly FullWord defaultWord; private MemoryFullWord realWord; - private readonly IMemory memory; + private readonly IMemory memory = memory; private readonly object syncRoot = new(); - public int Index { get; private set; } + public int Index => index; static VirtualMemoryFullWord() { @@ -36,18 +36,15 @@ static VirtualMemoryFullWord() } } - public VirtualMemoryFullWord(IMemory memory, int index) - { - this.memory = memory; - Index = index; - } - public int BitCount => defaultWord.BitCount; public int ByteCount => FullWord.ByteCount; + public int Count + => ByteCount; + private FullWord ActiveWord => RealWordFetched ? this.realWord : defaultWord; @@ -60,8 +57,8 @@ public long ProfilingTickCount public long ProfilingExecutionCount => RealWordFetched ? this.realWord.ProfilingExecutionCount : 0; - public IEnumerator GetEnumerator() - => ActiveWord.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() + => ((IEnumerable)ActiveWord).GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)ActiveWord).GetEnumerator(); @@ -73,7 +70,10 @@ public bool IsEmpty => !RealWordFetched || this.realWord.IsEmpty; public MixByte[] ToArray() - => ActiveWord.ToArray(); + => [..ActiveWord]; + + public MixByte[] Slice(int startIndex, int count) + => ActiveWord.Slice(startIndex, count); public object Clone() => ActiveWord.Clone(); diff --git a/src/MixLib/Type/Word.cs b/src/MixLib/Type/Word.cs index c43d627..696bf5a 100644 --- a/src/MixLib/Type/Word.cs +++ b/src/MixLib/Type/Word.cs @@ -51,6 +51,9 @@ public void Load(string text) public virtual bool IsEmpty => MagnitudeLongValue == 0 && Sign.IsPositive(); + public int Count + => ByteCount; + public int MaxByteCount => ByteCount; @@ -63,7 +66,7 @@ public long MaxMagnitude public override string ToString() => ToString(false); - public IEnumerator GetEnumerator() + IEnumerator IEnumerable.GetEnumerator() => this.bytes.GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() @@ -90,6 +93,16 @@ public static long BytesToLong(Signs sign, params MixByte[] bytes) return longValue; } + public MixByte[] Slice(int startIndex, int count) + { + MixByte[] slice = new MixByte[count]; + + for (int i = 0; i < count; i++) + slice[i] = this.bytes[startIndex + i]; + + return slice; + } + public void InvertSign() => Sign = Sign.Invert(); From 680fadde75edacc4c00b44adefb74560e463d12f Mon Sep 17 00:00:00 2001 From: Rutger van Bergen Date: Fri, 23 Aug 2024 12:46:53 +0200 Subject: [PATCH 2/3] Bump version to 0.5.1.2 --- src/SolutionInfo.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SolutionInfo.cs b/src/SolutionInfo.cs index 1defa6a..5015442 100644 --- a/src/SolutionInfo.cs +++ b/src/SolutionInfo.cs @@ -3,7 +3,7 @@ [assembly: AssemblyCompany("Rutger van Bergen")] [assembly: AssemblyProduct("MixEmul")] -[assembly: AssemblyCopyright("© Copyright 2023, Rutger van Bergen")] +[assembly: AssemblyCopyright("© Copyright 2024, Rutger van Bergen")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] [assembly: AssemblyConfiguration("")] @@ -16,5 +16,5 @@ // Build Number // Revision // -[assembly: AssemblyVersion("0.5.1.1")] -[assembly: AssemblyFileVersion("0.5.1.1")] +[assembly: AssemblyVersion("0.5.1.2")] +[assembly: AssemblyFileVersion("0.5.1.2")] From 30109911791a8f849a72c374a3d88aa17cb18588 Mon Sep 17 00:00:00 2001 From: Rutger van Bergen Date: Fri, 23 Aug 2024 12:53:18 +0200 Subject: [PATCH 3/3] Missed one --- src/MixAssembler/Finding/AssemblyFinding.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/MixAssembler/Finding/AssemblyFinding.cs b/src/MixAssembler/Finding/AssemblyFinding.cs index 68d88f4..f0acf1b 100644 --- a/src/MixAssembler/Finding/AssemblyFinding.cs +++ b/src/MixAssembler/Finding/AssemblyFinding.cs @@ -5,11 +5,11 @@ namespace MixAssembler.Finding public abstract class AssemblyFinding(Severity severity, int lineNumber, LineSection section, int startCharIndex, int length) { - public int Length { get; private set; } = length; - public int LineNumber { get; private set; } = lineNumber; - public LineSection LineSection { get; private set; } = section; - public Severity Severity { get; private set; } = severity; - public int StartCharIndex { get; private set; } = startCharIndex; + public int Length => length; + public int LineNumber => lineNumber; + public LineSection LineSection => section; + public Severity Severity => severity; + public int StartCharIndex => startCharIndex; public const int NoNumber = int.MinValue;