Skip to content

Commit c582773

Browse files
authored
Implement small classes (#1259)
Signed-off-by: AnErrupTion <anerruption@disroot.org>
1 parent 0c00d73 commit c582773

File tree

19 files changed

+299
-634
lines changed

19 files changed

+299
-634
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Copyright (c) MOSA Project. Licensed under the New BSD License.
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Reflection;
5+
using System.Runtime.CompilerServices;
6+
7+
namespace Internal;
8+
9+
internal static class Impl
10+
{
11+
public static class Debug
12+
{
13+
public const string NoMessage = "No message";
14+
public const string NoDetails = "No details";
15+
public const string NoCategory = "No category";
16+
public const string NoValue = "No value";
17+
public const string FailText = "{0}\nDetails: {1}"; // {0} = Message, {1} = Details
18+
public const string WriteText = "DEBUG ({0}): {1}"; // {0} = Category, {1} = Value/Message
19+
}
20+
21+
public static class ConstructorInfo
22+
{
23+
public const string ConstructorName = ".ctor";
24+
public const string TypeConstructorName = ".cctor";
25+
}
26+
27+
public static class RuntimeHelpers
28+
{
29+
[MethodImpl(MethodImplOptions.InternalCall)]
30+
public static extern void InitializeArray(Array array, RuntimeFieldHandle fldHandle);
31+
32+
[MethodImpl(MethodImplOptions.InternalCall)]
33+
public static extern int GetHashCode(object o);
34+
35+
[MethodImpl(MethodImplOptions.InternalCall)]
36+
public new static extern bool Equals(object o1, object o2);
37+
38+
[MethodImpl(MethodImplOptions.InternalCall)]
39+
public static extern T UnsafeCast<T>(object o) where T : class;
40+
41+
[MethodImpl(MethodImplOptions.InternalCall)]
42+
public static extern IEnumerable<Assembly> GetAssemblies();
43+
44+
[MethodImpl(MethodImplOptions.InternalCall)]
45+
public static extern object CreateInstance(Type type, params object[] args);
46+
47+
// The body of this function will be replaced by the EE with unsafe code
48+
// See getILIntrinsicImplementation for how this happens.
49+
[Intrinsic]
50+
public static bool EnumEquals<T>(T x, T y) where T : Enum => x.Equals(y);
51+
52+
[Intrinsic]
53+
public static bool IsReferenceOrContainsReferences<T>() => throw new InvalidOperationException();
54+
}
55+
56+
public static class Bmi1
57+
{
58+
[MethodImpl(MethodImplOptions.InternalCall)]
59+
public static extern uint ResetLowestSetBit(uint value);
60+
61+
[MethodImpl(MethodImplOptions.InternalCall)]
62+
public static extern uint TrailingZeroCount(uint value);
63+
}
64+
65+
public static class Lzcnt
66+
{
67+
[MethodImpl(MethodImplOptions.InternalCall)]
68+
public static extern uint LeadingZeroCount(uint value);
69+
}
70+
71+
public static class Popcnt
72+
{
73+
[MethodImpl(MethodImplOptions.InternalCall)]
74+
public static extern uint PopCount(uint value);
75+
}
76+
77+
public static class Object
78+
{
79+
[MethodImpl(MethodImplOptions.InternalCall)]
80+
public static extern Type GetType(object obj);
81+
82+
[MethodImpl(MethodImplOptions.InternalCall)]
83+
public static extern Type MemberwiseClone(object obj);
84+
}
85+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (c) MOSA Project. Licensed under the New BSD License.
2+
3+
namespace System.Runtime.CompilerServices;
4+
5+
/// <summary>
6+
/// Reserved by the compiler for tracking intrinsics.
7+
/// </summary>
8+
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Field, Inherited = false)]
9+
internal sealed class IntrinsicAttribute : Attribute;

Source/Mosa.TinyCoreLib/System.Buffers/MemoryHandle.cs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,33 @@ namespace System.Buffers;
44

55
public struct MemoryHandle : IDisposable
66
{
7-
private object _dummy;
7+
private unsafe void* pointer;
8+
private GCHandle handle;
9+
private IPinnable? pinnable;
810

9-
private int _dummyPrimitive;
11+
[CLSCompliant(false)] public unsafe void* Pointer => pointer;
1012

1113
[CLSCompliant(false)]
12-
public unsafe void* Pointer
14+
public unsafe MemoryHandle(void* pointer, GCHandle handle = default, IPinnable? pinnable = null)
1315
{
14-
get
15-
{
16-
throw null;
17-
}
18-
}
19-
20-
[CLSCompliant(false)]
21-
public unsafe MemoryHandle(void* pointer, GCHandle handle = default(GCHandle), IPinnable? pinnable = null)
22-
{
23-
throw null;
16+
this.pointer = pointer;
17+
this.handle = handle;
18+
this.pinnable = pinnable;
2419
}
2520

2621
public void Dispose()
2722
{
23+
handle.Free();
24+
25+
if (pinnable != null)
26+
{
27+
pinnable.Unpin();
28+
pinnable = null;
29+
}
30+
31+
unsafe
32+
{
33+
pointer = null;
34+
}
2835
}
2936
}

0 commit comments

Comments
 (0)