Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion Source/Mosa.Linux.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31912.275
MinimumVisualStudioVersion = 12.0.31101.0
Expand Down Expand Up @@ -235,6 +235,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mosa.Utility.CreateCoreLib"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mosa.TinyCoreLib", "Mosa.TinyCoreLib\Mosa.TinyCoreLib.csproj", "{844037C4-B018-4AD0-8237-BAE46E024994}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mosa.UnitTests.TinyCoreLib", "Mosa.UnitTests.TinyCoreLib\Mosa.UnitTests.TinyCoreLib.csproj", "{F74513A5-E5B4-4ABC-9E8B-999EC55FCFC6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1347,6 +1349,24 @@ Global
{844037C4-B018-4AD0-8237-BAE46E024994}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{844037C4-B018-4AD0-8237-BAE46E024994}.Release|x86.ActiveCfg = Release|Any CPU
{844037C4-B018-4AD0-8237-BAE46E024994}.Release|x86.Build.0 = Release|Any CPU
{F74513A5-E5B4-4ABC-9E8B-999EC55FCFC6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F74513A5-E5B4-4ABC-9E8B-999EC55FCFC6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F74513A5-E5B4-4ABC-9E8B-999EC55FCFC6}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{F74513A5-E5B4-4ABC-9E8B-999EC55FCFC6}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{F74513A5-E5B4-4ABC-9E8B-999EC55FCFC6}.Debug|x86.ActiveCfg = Debug|Any CPU
{F74513A5-E5B4-4ABC-9E8B-999EC55FCFC6}.Debug|x86.Build.0 = Debug|Any CPU
{F74513A5-E5B4-4ABC-9E8B-999EC55FCFC6}.Description|Any CPU.ActiveCfg = Debug|Any CPU
{F74513A5-E5B4-4ABC-9E8B-999EC55FCFC6}.Description|Any CPU.Build.0 = Debug|Any CPU
{F74513A5-E5B4-4ABC-9E8B-999EC55FCFC6}.Description|Mixed Platforms.ActiveCfg = Debug|Any CPU
{F74513A5-E5B4-4ABC-9E8B-999EC55FCFC6}.Description|Mixed Platforms.Build.0 = Debug|Any CPU
{F74513A5-E5B4-4ABC-9E8B-999EC55FCFC6}.Description|x86.ActiveCfg = Debug|Any CPU
{F74513A5-E5B4-4ABC-9E8B-999EC55FCFC6}.Description|x86.Build.0 = Debug|Any CPU
{F74513A5-E5B4-4ABC-9E8B-999EC55FCFC6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F74513A5-E5B4-4ABC-9E8B-999EC55FCFC6}.Release|Any CPU.Build.0 = Release|Any CPU
{F74513A5-E5B4-4ABC-9E8B-999EC55FCFC6}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{F74513A5-E5B4-4ABC-9E8B-999EC55FCFC6}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{F74513A5-E5B4-4ABC-9E8B-999EC55FCFC6}.Release|x86.ActiveCfg = Release|Any CPU
{F74513A5-E5B4-4ABC-9E8B-999EC55FCFC6}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
86 changes: 70 additions & 16 deletions Source/Mosa.TinyCoreLib/Internal/Exceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,79 @@ namespace Internal;

internal static class Exceptions
{
public const string Exception = "An exception was thrown.";
public const string PlatformNotSupportedException = "The platform is not supported.";
public const string InvalidOperationException = "The requested operation cannot be performed.";
public const string NotSupportedException = "The operation is not supported.";
public const string NotImplementedException = "The operation is not implemented.";
public const string RankException = "Attempted to operate on an array with an incorrect number of dimensions.";
public const string ArgumentException = "The value does not fall within the expected range.";
public const string ArithmeticException = "An arithmetic, casting, or conversion error occured.";
public const string SystemException = "A system exception was thrown.";
public const string OverflowException = "A checked arithmetic, casting, or conversion operation resulted in an overflow.";
public const string FormatException = "An invalid format argument was passed, or a composite format string is malformed.";
public const string IndexOutOfRangeException = "The index was outside the bounds of the array.";
public const string ArgumentNullException = "The argument cannot be null.";
public const string ArgumentOutOfRangeException = "The argument is out of range.";
public const string ObjectDisposedException = "The object was used after being disposed.";
public const string TypeLoadException = "A failure has occured while loading a type.";
public const string Exception = "An exception was thrown.";
public const string PlatformNotSupportedException = "The platform is not supported.";
public const string InvalidOperationException = "The requested operation cannot be performed.";
public const string NotSupportedException = "The operation is not supported.";
public const string NotImplementedException = "The operation is not implemented.";
public const string RankException = "Attempted to operate on an array with an incorrect number of dimensions.";
public const string ArgumentException = "The value does not fall within the expected range.";
public const string ArithmeticException = "An arithmetic, casting, or conversion error occured.";
public const string SystemException = "A system exception was thrown.";
public const string OverflowException = "A checked arithmetic, casting, or conversion operation resulted in an overflow.";
public const string FormatException = "An invalid format argument was passed, or a composite format string is malformed.";
public const string IndexOutOfRangeException = "The index was outside the bounds of the array.";
public const string ArgumentNullException = "The argument cannot be null.";
public const string ArgumentOutOfRangeException = "The argument is out of range.";
public const string ObjectDisposedException = "The object was used after being disposed.";
public const string TypeLoadException = "A failure has occured while loading a type.";

public static class Generic
{
[DoesNotReturn] public static void ParameterOutOfRange(string name) => throw new ArgumentOutOfRangeException(name);
[DoesNotReturn] public static void ThrowMultiDimensionalArrayException(string name) => throw new ArgumentException("The array has more than one dimension.", name);
[DoesNotReturn] public static void ThrowArrayNotZeroBasedIndexingException(string name) => throw new ArgumentException("The array doesn't use zero-based indexing.", name);
[DoesNotReturn] public static void ThrowArrayTypeMismatchException(string name) => throw new ArgumentException("The array's element type doesn't match the collection's element type.", name);
}

public static class LinkedList
{
public static class Enumerator
{
[DoesNotReturn] public static void ThrowListModifiedException() => throw new InvalidOperationException("The list was modified after the enumerator was created.");
}

[DoesNotReturn] public static void ThrowNodeNotInListException() => throw new InvalidOperationException("The node is not in the list.");
[DoesNotReturn] public static void ThrowNewNodeInAnotherListException() => throw new InvalidOperationException("The new node is already in another list.");
[DoesNotReturn] public static void ThrowListTooBigException(string name) => throw new ArgumentException("The list is too big for the destination array.", name);
[DoesNotReturn] public static void ThrowListEmptyException(string name) => throw new ArgumentException("The list is empty.", name);
}

public static class Stack
{
public static class Enumerator
{
[DoesNotReturn] public static void ThrowStackModifiedException() => throw new InvalidOperationException("The stack was modified after the enumerator was created.");
}

[DoesNotReturn] public static void ThrowStackTooBigException(string name) => throw new ArgumentException("The stack is too big for the destination array.", name);
[DoesNotReturn] public static void ThrowStackEmptyException() => throw new InvalidOperationException("The stack is empty.");
}

public static class Queue
{
public static class Enumerator
{
[DoesNotReturn] public static void ThrowQueueModifiedException() => throw new InvalidOperationException("The queue was modified after the enumerator was created.");
}

[DoesNotReturn] public static void ThrowQueueTooBigException(string name) => throw new ArgumentException("The queue is too big for the destination array.", name);
}

public static class List
{
public static class Enumerator
{
[DoesNotReturn] public static void ThrowListModifiedException() => throw new InvalidOperationException("The list was modified after the enumerator was created.");
}

[DoesNotReturn] public static void ThrowValueIncorrectTypeException(string name) => throw new ArgumentException("The value's type is different from the list's element type.", name);
[DoesNotReturn] public static void ThrowIndexOutOfBoundsException(string name) => throw new ArgumentException("The index is greater or equal to the list's element count.", name);
[DoesNotReturn] public static void ThrowListTooBigException(string name) => throw new ArgumentException("The list is too big for the destination array.", name);
}

public static class EqualityComparer
{
[DoesNotReturn] public static void ThrowInvalidTypeException(string name) => throw new ArgumentException("The parameter is of a type that cannot be cast to the compared type.", name);
}
}
18 changes: 18 additions & 0 deletions Source/Mosa.TinyCoreLib/Internal/Impl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,22 @@ public static class Object
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern Type MemberwiseClone(object obj);
}

public static class Queue
{
public const int InitialArraySize = 16;
public const double NextCapacityMultiplySize = 1.1;
}

public static class List
{
public const int InitialArraySize = 16;
public const double NextCapacityMultiplySize = 1.1;
public const double CapacityTrimThreshold = 0.9;
}

public static class Stack
{
public const int InitialArraySize = 16;
}
}
21 changes: 21 additions & 0 deletions Source/Mosa.TinyCoreLib/Internal/SimpleEqualityComparer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

namespace Internal;

public class SimpleEqualityComparer<T> : EqualityComparer<T>
{
public override bool Equals(T? x, T? y)
{
if (x is null || y is null)
return x is null && y is null;

if (x is IEquatable<T> xEq && y is IEquatable<T> yEq)
return xEq.Equals(yEq);

return x.Equals(y);
}

public override int GetHashCode([DisallowNull] T obj) => obj.GetHashCode();
}
12 changes: 12 additions & 0 deletions Source/Mosa.TinyCoreLib/Internal/SpecificEqualityComparer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

namespace Internal;

public class SpecificEqualityComparer<T>(Func<T, T, bool> equals, Func<T, int>? getHashCode) : EqualityComparer<T>
{
public override bool Equals(T? x, T? y) => equals(x, y);

public override int GetHashCode([DisallowNull] T obj) => getHashCode is null ? throw new NotSupportedException() : getHashCode(obj);
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ namespace System.Collections.Generic;

public abstract class EqualityComparer<T> : IEqualityComparer<T>, IEqualityComparer
{
public static EqualityComparer<T> Default
{
get
{
throw null;
}
}
public static EqualityComparer<T> Default { get; } = new Internal.SimpleEqualityComparer<T>();

public static EqualityComparer<T> Create(Func<T?, T?, bool> equals, Func<T, int>? getHashCode = null)
{
throw null;
ArgumentNullException.ThrowIfNull(equals);

return new Internal.SpecificEqualityComparer<T>(equals, getHashCode);
}

public abstract bool Equals(T? x, T? y);
Expand All @@ -23,11 +19,31 @@ public static EqualityComparer<T> Create(Func<T?, T?, bool> equals, Func<T, int>

bool IEqualityComparer.Equals(object? x, object? y)
{
throw null;
if (x is null || y is null)
return false;

if (x is T a)
{
if (y is T b)
return a.Equals(b);

Internal.Exceptions.EqualityComparer.ThrowInvalidTypeException(nameof(y));
return false;
}

Internal.Exceptions.EqualityComparer.ThrowInvalidTypeException(nameof(x));
return false;
}

int IEqualityComparer.GetHashCode(object obj)
{
throw null;
// Implementation detail: Even if "obj" is a value type, we accept null and just return 0.
// This is different from the documentation which tells us to throw an exception if "obj"
// is a reference type and "obj" is null.
if (obj is null) return 0;
if (obj is T value) return GetHashCode(value);

Internal.Exceptions.EqualityComparer.ThrowInvalidTypeException(nameof(obj));
return 0;
}
}

This file was deleted.

This file was deleted.

Loading
Loading