Skip to content

Commit 66680c9

Browse files
Version 3.1.1.1
1 parent 502933c commit 66680c9

File tree

9 files changed

+53
-46
lines changed

9 files changed

+53
-46
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
6502.Net, A .Net-Based Cross-Assembler for Several 8-Bit Microprocessors.
22

3-
Version 3.1
3+
Version 3.1.1
44

55
## Overview
66

Sixty502DotNet.Tests/Sixty502DotNet.Tests.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
<TargetFramework>net5.0</TargetFramework>
55

66
<IsPackable>false</IsPackable>
7-
<ReleaseVersion>3.1.0.1</ReleaseVersion>
7+
<ReleaseVersion>3.1.1.1</ReleaseVersion>
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
12-
<PackageReference Include="MSTest.TestAdapter" Version="2.2.9" />
13-
<PackageReference Include="MSTest.TestFramework" Version="2.2.9" />
11+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
12+
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
13+
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
1414
<PackageReference Include="coverlet.collector" Version="3.1.2"><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1515
<PrivateAssets>all</PrivateAssets>
1616
</PackageReference>

Sixty502DotNet.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Global
4040
SolutionGuid = {9BE7575F-6E99-4243-AEAA-4D1E1064DA97}
4141
EndGlobalSection
4242
GlobalSection(MonoDevelopProperties) = preSolution
43-
version = 3.1.0.1
43+
version = 3.1.1.1
4444
Policies = $0
4545
$0.VersionControlPolicy = $1
4646
$1.CommitMessageStyle = $2

Sixty502DotNet/Sixty502DotNet.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
<TargetFramework>net5.0</TargetFramework>
66
<RollForward>Major</RollForward>
77
<PackageId>6502.Net</PackageId>
8-
<Version>3.1.0.1</Version>
8+
<Version>3.1.1.1</Version>
99
<Authors>informedcitizenry</Authors>
1010
<Company>informedcitizenry</Company>
1111
<Product>6502.Net</Product>
1212
<Description>6502.Net, A .Net Cross Assembler for Several 8-Bit Microprocessors.</Description>
1313
<Copyright>(C) Copyright 2017-2022 informedcitizenry</Copyright>
14-
<ReleaseVersion>3.1.0.1</ReleaseVersion>
14+
<ReleaseVersion>3.1.1.1</ReleaseVersion>
1515
<StartupObject>Sixty502DotNet.Program</StartupObject>
1616
<AssemblyName>6502.Net</AssemblyName>
17-
<AssemblyVersion>3.1.0.1</AssemblyVersion>
18-
<FileVersion>3.1.0.1</FileVersion>
17+
<AssemblyVersion>3.1.1.1</AssemblyVersion>
18+
<FileVersion>3.1.1.1</FileVersion>
1919
<SignAssembly>false</SignAssembly>
2020
<LangVersion>8.0</LangVersion>
2121
<Nullable>enable</Nullable>

Sixty502DotNet/src/ExpressionEvaluation/Converters/BinaryConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class BinaryDoubleConverter : ICustomConverter
4949
public Value Convert(string str)
5050
{
5151
string bString = str[0] == '%' ? str[1..] : str[2..];
52-
return new Value(NumberConverter.GetDoubleAtBase(bString, 2));
52+
return NumberConverter.GetDoubleAtBase(bString, 2);
5353
}
5454
}
5555
}

Sixty502DotNet/src/ExpressionEvaluation/Converters/HexConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public Value Convert(string str)
1919
Value hexVal = str[0] == '$' ?
2020
new Value(System.Convert.ToInt64(str[1..], 16)) :
2121
new Value(System.Convert.ToInt64(str[2..], 16));
22-
return Evaluator.ConvertToIntegral(hexVal);
22+
return NumberConverter.ConvertToIntegral(hexVal);
2323
}
2424
}
2525

@@ -32,7 +32,7 @@ public class HexDoubleConverter : ICustomConverter
3232
public Value Convert(string str)
3333
{
3434
var hString = str[0] == '$' ? str[1..] : str[2..];
35-
return new Value(NumberConverter.GetDoubleAtBase(hString, 16));
35+
return NumberConverter.GetDoubleAtBase(hString, 16);
3636
}
3737
}
3838
}

Sixty502DotNet/src/ExpressionEvaluation/Converters/NumberConverter.cs

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class NumberConverter : ICustomConverter
2828
/// <param name="str">The non-decimal string.</param>
2929
/// <param name="atBase">The number base.</param>
3030
/// <returns>The converted string as a double.</returns>
31-
public static double GetDoubleAtBase(string str, int atBase)
31+
public static Value GetDoubleAtBase(string str, int atBase)
3232
{
3333
var regex = atBase == 16 ? s_hexDoubleParserRegex : s_nonHexDoubleParserRegex;
3434
var mantissaExponent = regex.Match(str.Replace("_", ""));
@@ -40,10 +40,33 @@ public static double GetDoubleAtBase(string str, int atBase)
4040
if (mantissaExponent.Groups.Count > 2 && mantissaExponent.Groups[3].Success)
4141
{
4242
var base_ = mantissaExponent.Groups[2].Value.ToLower()[0] == 'e' ? 10 : 2;
43-
var exponentent = double.Parse(mantissaExponent.Groups[3].Value);
44-
return mantissa * Math.Pow(base_, exponentent);
43+
var exponent = double.Parse(mantissaExponent.Groups[3].Value);
44+
return new Value(mantissa * Math.Pow(base_, exponent));
4545
}
46-
return mantissa;
46+
return new Value(mantissa);
47+
}
48+
49+
/// <summary>
50+
/// Convert a <see cref="double"/> to an <see cref="int"/> or
51+
/// <see cref="uint"/> if the converted value is able to be converted.
52+
/// Otherwise, the returned value is the original value itself.
53+
/// </summary>
54+
/// <param name="value">The <see cref="double"/> as an <see cref="IValue"/>.
55+
/// </param>
56+
/// <returns>The converted <see cref="int"/> or <see cref="uint"/> as an
57+
/// <see cref="Value"/> if conversion was successful, otherwise the
58+
/// original value itself.</returns>
59+
public static Value ConvertToIntegral(Value value)
60+
{
61+
if (value.ToDouble() >= int.MinValue && value.ToDouble() <= uint.MaxValue)
62+
{
63+
if (value.ToDouble() <= int.MaxValue)
64+
{
65+
return new Value(unchecked((int)(value.ToLong() & 0xFFFF_FFFF)));
66+
}
67+
return new Value((uint)(value.ToLong() & 0xFFFF_FFFF));
68+
}
69+
return value;
4770
}
4871

4972
public Value Convert(string str)
@@ -53,15 +76,15 @@ public Value Convert(string str)
5376
{
5477
if (!char.IsDigit(str[1]))
5578
{
56-
return Evaluator.ConvertToIntegral(new Value(System.Convert.ToInt64(str[2..], 8)));
79+
return ConvertToIntegral(new Value(System.Convert.ToInt64(str[2..], 8)));
5780
}
58-
return Evaluator.ConvertToIntegral(new Value(System.Convert.ToInt64(str, 8)));
81+
return ConvertToIntegral(new Value(System.Convert.ToInt64(str, 8)));
5982
}
6083
var numVal = new Value(System.Convert.ToDouble(str));
6184
bool isDouble = str.IndexOf('.') > -1 || str.IndexOf('e') > -1 || str.IndexOf('E') > -1;
6285
if (!isDouble)
6386
{
64-
return Evaluator.ConvertToIntegral(numVal);
87+
return ConvertToIntegral(numVal);
6588
}
6689
return numVal;
6790
}
@@ -76,7 +99,7 @@ public class OctalDoubleConverter : ICustomConverter
7699
public Value Convert(string str)
77100
{
78101
string octalStr = !char.IsDigit(str[1]) ? str[2..] : str[1..];
79-
return new Value(NumberConverter.GetDoubleAtBase(octalStr, 8));
102+
return NumberConverter.GetDoubleAtBase(octalStr, 8);
80103
}
81104
}
82105
}

Sixty502DotNet/src/ExpressionEvaluation/Evaluator.cs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -347,29 +347,6 @@ public static Value CondOp(Value cond, Value then, Value els)
347347
throw new InvalidOperationException(Errors.TypeMismatchError);
348348
}
349349

350-
/// <summary>
351-
/// Convert a <see cref="double"/> to an <see cref="int"/> or
352-
/// <see cref="uint"/> if the converted value is able to be converted.
353-
/// Otherwise, the returned value is the original value itself.
354-
/// </summary>
355-
/// <param name="value">The <see cref="double"/> as an <see cref="IValue"/>.
356-
/// </param>
357-
/// <returns>The converted <see cref="int"/> or <see cref="uint"/> as an
358-
/// <see cref="Value"/> if conversion was successful, otherwise the
359-
/// original value itself.</returns>
360-
public static Value ConvertToIntegral(Value value)
361-
{
362-
if (value.ToDouble() >= int.MinValue && value.ToDouble() <= uint.MaxValue)
363-
{
364-
if (value.ToDouble() <= int.MaxValue)
365-
{
366-
return new Value(unchecked((int)(value.ToLong() & 0xFFFF_FFFF)));
367-
}
368-
return new Value((uint)(value.ToLong() & 0xFFFF_FFFF));
369-
}
370-
return value;
371-
}
372-
373350
private static bool ExpressionContainsPC(Sixty502DotNetParser.ExprContext context)
374351
{
375352
if (context.refExpr()?.programCounter() != null)

Sixty502DotNet/src/ExpressionEvaluation/ValueTypes/Value.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public virtual bool Equals(Value? other)
7777
{
7878
if (IsNumeric && other.IsNumeric == true)
7979
{
80-
return ToDouble() == other.ToDouble();
80+
return Math.Abs(ToDouble() - other.ToDouble()) < 0.0000001;
8181
}
8282
if (IsString && other.IsString || (DotNetType == TypeCode.Char && other.DotNetType == TypeCode.Char))
8383
{
@@ -92,7 +92,14 @@ public virtual bool Equals(Value? other)
9292
/// Get the value's hash code.
9393
/// </summary>
9494
/// <returns>A hash code for the current object.</returns>
95-
public override int GetHashCode() => Data.GetHashCode();
95+
public override int GetHashCode()
96+
{
97+
if (DotNetType != TypeCode.Double)
98+
{
99+
return Data.GetHashCode();
100+
}
101+
return Math.Round((double)Data, 7).GetHashCode();
102+
}
96103

97104
/// <summary>
98105
/// Determine if this value is equal to another object.

0 commit comments

Comments
 (0)