Skip to content

Commit

Permalink
.NET 8 improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
rbergen committed Dec 10, 2023
1 parent bf26a2c commit 9beb16a
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 188 deletions.
12 changes: 6 additions & 6 deletions src/MixAssembler/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,18 +254,18 @@ private static string[] SplitLine(string sourceLine)
var opFieldStart = FindFirstNonWhiteSpace(sourceLine, searchBeyondIndex);

if (opFieldStart == -1)
return new string[] { sourceLine.Substring(0, searchBeyondIndex), string.Empty, string.Empty, string.Empty };
return new string[] { sourceLine[..searchBeyondIndex], string.Empty, string.Empty, string.Empty };

var opFieldEnd = FindFirstWhiteSpace(sourceLine, opFieldStart);

if (opFieldEnd == -1)
return new string[] { sourceLine.Substring(0, searchBeyondIndex), sourceLine[opFieldStart..], string.Empty, string.Empty };
return new string[] { sourceLine[..searchBeyondIndex], sourceLine[opFieldStart..], string.Empty, string.Empty };

int opFieldLength = opFieldEnd - opFieldStart;
var addressFieldStart = FindFirstNonWhiteSpace(sourceLine, opFieldEnd);

if (addressFieldStart == -1)
return new string[] { sourceLine.Substring(0, searchBeyondIndex), sourceLine.Substring(opFieldStart, opFieldLength), string.Empty, string.Empty };
return new string[] { sourceLine[..searchBeyondIndex], sourceLine.Substring(opFieldStart, opFieldLength), string.Empty, string.Empty };

if (sourceLine[addressFieldStart] == '"')
{
Expand All @@ -280,15 +280,15 @@ private static string[] SplitLine(string sourceLine)
addressFieldEnd = FindFirstWhiteSpace(sourceLine, addressFieldStart);

if (addressFieldEnd == -1)
return new string[] { sourceLine.Substring(0, searchBeyondIndex), sourceLine.Substring(opFieldStart, opFieldLength), sourceLine[addressFieldStart..], string.Empty };
return new string[] { 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.Substring(0, searchBeyondIndex), sourceLine.Substring(opFieldStart, opFieldLength), sourceLine.Substring(addressFieldStart, addressFieldLength), string.Empty };
return new string[] { sourceLine[..searchBeyondIndex], sourceLine.Substring(opFieldStart, opFieldLength), sourceLine.Substring(addressFieldStart, addressFieldLength), "" };

return new string[] { sourceLine.Substring(0, searchBeyondIndex), sourceLine.Substring(opFieldStart, opFieldLength), sourceLine.Substring(addressFieldStart, addressFieldLength), sourceLine[commentFieldStart..] };
return new string[] { sourceLine[..searchBeyondIndex], sourceLine.Substring(opFieldStart, opFieldLength), sourceLine.Substring(addressFieldStart, addressFieldLength), sourceLine[commentFieldStart..] };
}
}
}
7 changes: 2 additions & 5 deletions src/MixEmul/Components/AssemblyFindingListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,9 @@ public int Compare(AssemblyFinding x, AssemblyFinding y)
}
}

public class SelectionChangedEventArgs : EventArgs
public class SelectionChangedEventArgs(AssemblyFinding finding) : EventArgs
{
private readonly AssemblyFinding mSelectedFinding;

public SelectionChangedEventArgs(AssemblyFinding finding)
=> mSelectedFinding = finding;
private readonly AssemblyFinding mSelectedFinding = finding;

public AssemblyFinding SelectedFinding => mSelectedFinding;
}
Expand Down
4 changes: 2 additions & 2 deletions src/MixEmul/Components/InstructionInstanceTextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private bool AssembleInstruction(bool markErrors)

var instance = Assembler.Assemble(Text, MemoryAddress, out ParsedSourceLine line, Symbols, out AssemblyFindingCollection findings);

if (instance != null && !(instance is MixInstruction.Instance))
if (instance != null && instance is not MixInstruction.Instance)
{
findings.Add(new AssemblyError(0, LineSection.OpField, 0, line.OpField.Length, new ValidationError("only MIX instruction mnemonics supported")));
instance = null;
Expand Down Expand Up @@ -553,7 +553,7 @@ public IWord WordValue
get => this.instructionWord;
set
{
if (!(value is IFullWord))
if (value is not IFullWord)
{
throw new ArgumentException("value must be an IFullWord");
}
Expand Down
20 changes: 6 additions & 14 deletions src/MixEmul/Components/LongValueTextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -433,22 +433,14 @@ public override string Text
set => CheckAndUpdateValue(value);
}

public class ValueChangedEventArgs : EventArgs
public class ValueChangedEventArgs(Word.Signs oldSign, long oldMagnitude, Word.Signs newSign, long newMagnitude) : EventArgs
{
public long OldMagnitude { get; private set; }
public Word.Signs OldSign { get; private set; }
public long NewMagnitude { get; private set; }
public Word.Signs NewSign { get; private set; }
public long OldMagnitude { get; private set; } = oldMagnitude;
public Word.Signs OldSign { get; private set; } = oldSign;
public long NewMagnitude { get; private set; } = newMagnitude;
public Word.Signs NewSign { get; private set; } = newSign;

public ValueChangedEventArgs(Word.Signs oldSign, long oldMagnitude, Word.Signs newSign, long newMagnitude)
{
OldMagnitude = oldMagnitude;
NewMagnitude = newMagnitude;
OldSign = oldSign;
NewSign = newSign;
}

public long NewValue
public long NewValue
=> NewSign.ApplyTo(NewMagnitude);

public long OldValue
Expand Down
4 changes: 2 additions & 2 deletions src/MixEmul/Components/MixByteCollectionCharTextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private void This_TextChanged(object sender, EventArgs e)
validText += c;

if (validText.Length > this.byteCollection.MaxByteCount)
validText = validText.Substring(0, this.byteCollection.MaxByteCount);
validText = validText[..this.byteCollection.MaxByteCount];

if (validText.Length > 0 || TextLength == 0)
{
Expand Down Expand Up @@ -281,7 +281,7 @@ public IMixByteCollection MixByteCollectionValue
this.byteCollection = value;

if (TextLength > this.byteCollection.MaxByteCount)
Text = Text.Substring(0, this.byteCollection.MaxByteCount);
Text = Text[..this.byteCollection.MaxByteCount];

Select(TextLength, 0);

Expand Down
14 changes: 4 additions & 10 deletions src/MixEmul/Components/MixByteTextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,11 @@ public sealed override string Text
set => CheckAndUpdateValue(value);
}

public class ValueChangedEventArgs : EventArgs
public class ValueChangedEventArgs(MixByte oldValue, MixByte newValue) : EventArgs
{
public MixByte NewValue { get; private set; }
public MixByte OldValue { get; private set; }

public ValueChangedEventArgs(MixByte oldValue, MixByte newValue)
{
OldValue = oldValue;
NewValue = newValue;
}
}
public MixByte NewValue { get; private set; } = newValue;
public MixByte OldValue { get; private set; } = oldValue;
}

public delegate void ValueChangedEventHandler(MixByteTextBox sender, MixByteTextBox.ValueChangedEventArgs e);
}
Expand Down
Loading

0 comments on commit 9beb16a

Please sign in to comment.