Skip to content

Commit

Permalink
Version 3.1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
informedcitizenry committed May 20, 2022
1 parent 502933c commit 66680c9
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 46 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
6502.Net, A .Net-Based Cross-Assembler for Several 8-Bit Microprocessors.

Version 3.1
Version 3.1.1

## Overview

Expand Down
8 changes: 4 additions & 4 deletions Sixty502DotNet.Tests/Sixty502DotNet.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<TargetFramework>net5.0</TargetFramework>

<IsPackable>false</IsPackable>
<ReleaseVersion>3.1.0.1</ReleaseVersion>
<ReleaseVersion>3.1.1.1</ReleaseVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.9" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.9" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="coverlet.collector" Version="3.1.2"><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion Sixty502DotNet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Global
SolutionGuid = {9BE7575F-6E99-4243-AEAA-4D1E1064DA97}
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
version = 3.1.0.1
version = 3.1.1.1
Policies = $0
$0.VersionControlPolicy = $1
$1.CommitMessageStyle = $2
Expand Down
8 changes: 4 additions & 4 deletions Sixty502DotNet/Sixty502DotNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
<TargetFramework>net5.0</TargetFramework>
<RollForward>Major</RollForward>
<PackageId>6502.Net</PackageId>
<Version>3.1.0.1</Version>
<Version>3.1.1.1</Version>
<Authors>informedcitizenry</Authors>
<Company>informedcitizenry</Company>
<Product>6502.Net</Product>
<Description>6502.Net, A .Net Cross Assembler for Several 8-Bit Microprocessors.</Description>
<Copyright>(C) Copyright 2017-2022 informedcitizenry</Copyright>
<ReleaseVersion>3.1.0.1</ReleaseVersion>
<ReleaseVersion>3.1.1.1</ReleaseVersion>
<StartupObject>Sixty502DotNet.Program</StartupObject>
<AssemblyName>6502.Net</AssemblyName>
<AssemblyVersion>3.1.0.1</AssemblyVersion>
<FileVersion>3.1.0.1</FileVersion>
<AssemblyVersion>3.1.1.1</AssemblyVersion>
<FileVersion>3.1.1.1</FileVersion>
<SignAssembly>false</SignAssembly>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class BinaryDoubleConverter : ICustomConverter
public Value Convert(string str)
{
string bString = str[0] == '%' ? str[1..] : str[2..];
return new Value(NumberConverter.GetDoubleAtBase(bString, 2));
return NumberConverter.GetDoubleAtBase(bString, 2);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public Value Convert(string str)
Value hexVal = str[0] == '$' ?
new Value(System.Convert.ToInt64(str[1..], 16)) :
new Value(System.Convert.ToInt64(str[2..], 16));
return Evaluator.ConvertToIntegral(hexVal);
return NumberConverter.ConvertToIntegral(hexVal);
}
}

Expand All @@ -32,7 +32,7 @@ public class HexDoubleConverter : ICustomConverter
public Value Convert(string str)
{
var hString = str[0] == '$' ? str[1..] : str[2..];
return new Value(NumberConverter.GetDoubleAtBase(hString, 16));
return NumberConverter.GetDoubleAtBase(hString, 16);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class NumberConverter : ICustomConverter
/// <param name="str">The non-decimal string.</param>
/// <param name="atBase">The number base.</param>
/// <returns>The converted string as a double.</returns>
public static double GetDoubleAtBase(string str, int atBase)
public static Value GetDoubleAtBase(string str, int atBase)
{
var regex = atBase == 16 ? s_hexDoubleParserRegex : s_nonHexDoubleParserRegex;
var mantissaExponent = regex.Match(str.Replace("_", ""));
Expand All @@ -40,10 +40,33 @@ public static double GetDoubleAtBase(string str, int atBase)
if (mantissaExponent.Groups.Count > 2 && mantissaExponent.Groups[3].Success)
{
var base_ = mantissaExponent.Groups[2].Value.ToLower()[0] == 'e' ? 10 : 2;
var exponentent = double.Parse(mantissaExponent.Groups[3].Value);
return mantissa * Math.Pow(base_, exponentent);
var exponent = double.Parse(mantissaExponent.Groups[3].Value);
return new Value(mantissa * Math.Pow(base_, exponent));
}
return mantissa;
return new Value(mantissa);
}

/// <summary>
/// Convert a <see cref="double"/> to an <see cref="int"/> or
/// <see cref="uint"/> if the converted value is able to be converted.
/// Otherwise, the returned value is the original value itself.
/// </summary>
/// <param name="value">The <see cref="double"/> as an <see cref="IValue"/>.
/// </param>
/// <returns>The converted <see cref="int"/> or <see cref="uint"/> as an
/// <see cref="Value"/> if conversion was successful, otherwise the
/// original value itself.</returns>
public static Value ConvertToIntegral(Value value)
{
if (value.ToDouble() >= int.MinValue && value.ToDouble() <= uint.MaxValue)
{
if (value.ToDouble() <= int.MaxValue)
{
return new Value(unchecked((int)(value.ToLong() & 0xFFFF_FFFF)));
}
return new Value((uint)(value.ToLong() & 0xFFFF_FFFF));
}
return value;
}

public Value Convert(string str)
Expand All @@ -53,15 +76,15 @@ public Value Convert(string str)
{
if (!char.IsDigit(str[1]))
{
return Evaluator.ConvertToIntegral(new Value(System.Convert.ToInt64(str[2..], 8)));
return ConvertToIntegral(new Value(System.Convert.ToInt64(str[2..], 8)));
}
return Evaluator.ConvertToIntegral(new Value(System.Convert.ToInt64(str, 8)));
return ConvertToIntegral(new Value(System.Convert.ToInt64(str, 8)));
}
var numVal = new Value(System.Convert.ToDouble(str));
bool isDouble = str.IndexOf('.') > -1 || str.IndexOf('e') > -1 || str.IndexOf('E') > -1;
if (!isDouble)
{
return Evaluator.ConvertToIntegral(numVal);
return ConvertToIntegral(numVal);
}
return numVal;
}
Expand All @@ -76,7 +99,7 @@ public class OctalDoubleConverter : ICustomConverter
public Value Convert(string str)
{
string octalStr = !char.IsDigit(str[1]) ? str[2..] : str[1..];
return new Value(NumberConverter.GetDoubleAtBase(octalStr, 8));
return NumberConverter.GetDoubleAtBase(octalStr, 8);
}
}
}
23 changes: 0 additions & 23 deletions Sixty502DotNet/src/ExpressionEvaluation/Evaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,29 +347,6 @@ public static Value CondOp(Value cond, Value then, Value els)
throw new InvalidOperationException(Errors.TypeMismatchError);
}

/// <summary>
/// Convert a <see cref="double"/> to an <see cref="int"/> or
/// <see cref="uint"/> if the converted value is able to be converted.
/// Otherwise, the returned value is the original value itself.
/// </summary>
/// <param name="value">The <see cref="double"/> as an <see cref="IValue"/>.
/// </param>
/// <returns>The converted <see cref="int"/> or <see cref="uint"/> as an
/// <see cref="Value"/> if conversion was successful, otherwise the
/// original value itself.</returns>
public static Value ConvertToIntegral(Value value)
{
if (value.ToDouble() >= int.MinValue && value.ToDouble() <= uint.MaxValue)
{
if (value.ToDouble() <= int.MaxValue)
{
return new Value(unchecked((int)(value.ToLong() & 0xFFFF_FFFF)));
}
return new Value((uint)(value.ToLong() & 0xFFFF_FFFF));
}
return value;
}

private static bool ExpressionContainsPC(Sixty502DotNetParser.ExprContext context)
{
if (context.refExpr()?.programCounter() != null)
Expand Down
11 changes: 9 additions & 2 deletions Sixty502DotNet/src/ExpressionEvaluation/ValueTypes/Value.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public virtual bool Equals(Value? other)
{
if (IsNumeric && other.IsNumeric == true)
{
return ToDouble() == other.ToDouble();
return Math.Abs(ToDouble() - other.ToDouble()) < 0.0000001;
}
if (IsString && other.IsString || (DotNetType == TypeCode.Char && other.DotNetType == TypeCode.Char))
{
Expand All @@ -92,7 +92,14 @@ public virtual bool Equals(Value? other)
/// Get the value's hash code.
/// </summary>
/// <returns>A hash code for the current object.</returns>
public override int GetHashCode() => Data.GetHashCode();
public override int GetHashCode()
{
if (DotNetType != TypeCode.Double)
{
return Data.GetHashCode();
}
return Math.Round((double)Data, 7).GetHashCode();
}

/// <summary>
/// Determine if this value is equal to another object.
Expand Down

0 comments on commit 66680c9

Please sign in to comment.