Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
022586f
Fix box/unbox Nullable<T> types
josesimoes Jul 7, 2025
6fb89fa
Merge branch 'develop' of https://github.com/nanoframework/nf-interpr…
josesimoes Jul 18, 2025
f5694b8
Replace SetGenericInstanceObject with SetGenericInstanceType
josesimoes Aug 5, 2025
aff8379
Fix creation of generic objects
josesimoes Aug 5, 2025
4803a77
Fix locals initialization
josesimoes Aug 7, 2025
5c84183
Move debug info about fields name to correct location
josesimoes Aug 7, 2025
534a980
Remove commented code
josesimoes Aug 7, 2025
e0c3b31
Fix FieldDef_Instance::ResolveToken
josesimoes Aug 7, 2025
cff66f0
Code style fixes
josesimoes Aug 7, 2025
d4f1beb
Code style fixes (#160)
nfbot Aug 7, 2025
d151656
Merge branch 'develop' of https://github.com/nanoframework/nf-interpr…
josesimoes Aug 12, 2025
bb1c2e1
Fix resolving type descriptor from TypeSpec token
josesimoes Aug 13, 2025
f3a70b7
Fix finding FieldDef for a generic instance
josesimoes Aug 13, 2025
677a8fa
TypeSpec instance now has a CLR_RT_TypeDef_Index
josesimoes Aug 13, 2025
1f52015
Fix DumpToken in info
josesimoes Aug 13, 2025
65dc497
Revert wrong trace config
josesimoes Aug 13, 2025
903e3db
Fix locals initialization for generic types
josesimoes Aug 18, 2025
cfab319
Fix initialization of TypeSpec from index
josesimoes Aug 18, 2025
024d976
Fix token resolution for TypeDef
josesimoes Aug 18, 2025
4c9f1dd
Fix field token resolution
josesimoes Aug 18, 2025
e93e8bb
Fix finding FieldDef
josesimoes Aug 18, 2025
a008b14
Remove unecessary code from MethodDef finder
josesimoes Aug 18, 2025
bfdb13e
Fix unboxing operation
josesimoes Aug 20, 2025
4c6ad00
Fix reflection for TypeSpec
josesimoes Aug 20, 2025
4701c18
Add new Initialize_TypeSpec to initialize from TypeSpec instance
josesimoes Aug 21, 2025
39944b7
Add IsAGenericInstance to Heapblock
josesimoes Aug 21, 2025
5babab3
Fix TypeDescriptor from generic type
josesimoes Aug 21, 2025
92f1eb1
Fix TypeDescriptor initialization from object
josesimoes Aug 21, 2025
beb14da
Fix extracting type index in TypeDescriptor
josesimoes Aug 21, 2025
036f260
ObjectGenericType in heap block now returns reflection data
josesimoes Aug 21, 2025
0a75279
Update declaration of mscorlib
josesimoes Aug 21, 2025
a7e957c
Add implementation for new methods in Type class
josesimoes Aug 21, 2025
10c46d8
Fix get_IsArray to deal with TypeSpecs
josesimoes Aug 21, 2025
7151fd6
Fix compiler errors
josesimoes Aug 21, 2025
b3d6213
Fix build error
josesimoes Aug 21, 2025
51889c0
Remove unused var
josesimoes Aug 21, 2025
b136778
Fix dangling pointer
josesimoes Aug 21, 2025
2996ca4
Fix pointer
josesimoes Aug 21, 2025
dba8b3d
Fix compiler errors
josesimoes Aug 21, 2025
5e5d3cf
Add Span_1 to project and class stub
josesimoes Aug 21, 2025
fd820e7
Replaced SpanByte with Span_1
josesimoes Aug 21, 2025
df4b419
Code style fixes (#161)
nfbot Aug 21, 2025
385670f
Add missing ref to Span<> source code
josesimoes Aug 21, 2025
09ba158
Fix InitializeReference for nested generic types
josesimoes Sep 1, 2025
de6bd51
Merge branch 'develop' of https://github.com/nanoframework/nf-interpr…
josesimoes Sep 4, 2025
1900db4
Fix mscorlib checksum
josesimoes Sep 4, 2025
4b03921
Add implementation for Span<T> CopyTo
josesimoes Sep 4, 2025
ed9126c
Fix token resolution for MethodDef when using empty generic types
josesimoes Sep 4, 2025
e2d8d6c
Fix local initialization for method in generic type
josesimoes Sep 4, 2025
ba315fc
Update mscorlib declaration with Span<T> and ReadOnlySpan<T>
josesimoes Sep 4, 2025
44c1c70
Fix Span<T> CopyTo
josesimoes Sep 4, 2025
9d8af32
Span<T> CopyTo now uses Array::Copy
josesimoes Sep 4, 2025
5bc67db
Fix ResolveToken for TypeDef when token is a TypeSpec
josesimoes Sep 4, 2025
e7651b6
Fix locals initialization for VAR signature with generic caller
josesimoes Sep 4, 2025
fdd237b
Fix DumpToken for MethodRef in generic types
josesimoes Sep 5, 2025
0e4891d
Fix token resolution for MedthoDef with generic instances
josesimoes Sep 5, 2025
642546b
Add missing levels processing in TypeDef instance from TypeSpec
josesimoes Sep 5, 2025
17167dc
Code style fixes (#163)
nfbot Sep 5, 2025
9ca1814
Fix compiler errors
josesimoes Sep 5, 2025
8c140de
Code style fixes (#164)
nfbot Sep 5, 2025
197503c
Fix compiler warning
josesimoes Sep 9, 2025
b99fad9
Fix resolving token from TypeSpec when creating an array
josesimoes Sep 9, 2025
f9b3f21
Code style fixes (#165)
nfbot Sep 9, 2025
f46021b
Missed previous commit
josesimoes Sep 9, 2025
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
2 changes: 2 additions & 0 deletions CMake/Modules/FindNF_CoreCLR.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,13 @@ set(NF_CoreCLR_SRCS
corlib_native_System_Number.cpp
corlib_native_System_Object.cpp
corlib_native_System_Random.cpp
corlib_native_System_ReadOnlySpan_1.cpp
corlib_native_System_Reflection_Binder.cpp
corlib_native_System_Reflection_MemberInfo.cpp
corlib_native_System_Runtime_CompilerServices_RuntimeHelpers.cpp
corlib_native_System_Runtime_Remoting_RemotingServices.cpp
corlib_native_System_String.cpp
corlib_native_System_Span_1.cpp
corlib_native_System_Threading_AutoResetEvent.cpp
corlib_native_System_Threading_Interlocked.cpp
corlib_native_System_Threading_ManualResetEvent.cpp
Expand Down
4 changes: 3 additions & 1 deletion src/CLR/CorLib/CorLib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<ClCompile Include="corlib_native_System_Number.cpp" />
<ClCompile Include="corlib_native_System_Object.cpp" />
<ClCompile Include="corlib_native_System_Random.cpp" />
<ClCompile Include="corlib_native_System_ReadOnlySpan_1.cpp" />
<ClCompile Include="corlib_native_System_Reflection_Assembly.cpp" />
<ClCompile Include="corlib_native_System_Reflection_Binder.cpp" />
<ClCompile Include="corlib_native_System_Reflection_ConstructorInfo.cpp" />
Expand All @@ -60,6 +61,7 @@
<ClCompile Include="corlib_native_System_RuntimeType.cpp" />
<ClCompile Include="corlib_native_System_Runtime_CompilerServices_RuntimeHelpers.cpp" />
<ClCompile Include="corlib_native_System_Runtime_Remoting_RemotingServices.cpp" />
<ClCompile Include="corlib_native_System_Span_1.cpp" />
<ClCompile Include="corlib_native_System_String.cpp" />
<ClCompile Include="corlib_native_System_Threading_AutoResetEvent.cpp" />
<ClCompile Include="corlib_native_System_Threading_Interlocked.cpp" />
Expand Down Expand Up @@ -208,4 +210,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
6 changes: 6 additions & 0 deletions src/CLR/CorLib/CorLib.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,11 @@
<ClCompile Include="corlib_native_System_Threading_SpinWait.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="corlib_native_System_Span_1.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="corlib_native_System_ReadOnlySpan_1.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
43 changes: 42 additions & 1 deletion src/CLR/CorLib/corlib_native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ static const CLR_RT_MethodHandler method_lookup[] =
Library_corlib_native_System_Reflection_FieldInfo::GetCustomAttributesNative___SZARRAY_OBJECT__BOOLEAN,
nullptr,
Library_corlib_native_System_Type::get_DeclaringType___SystemType,
Library_corlib_native_System_Type::GetGenericTypeDefinition___SystemType,
nullptr,
nullptr,
nullptr,
Expand All @@ -69,6 +70,7 @@ static const CLR_RT_MethodHandler method_lookup[] =
nullptr,
Library_corlib_native_System_Type::IsInstanceOfType___BOOLEAN__OBJECT,
nullptr,
Library_corlib_native_System_Type::GetGenericArguments___SZARRAY_SystemType,
Library_corlib_native_System_Type::InvokeMember___OBJECT__STRING__SystemReflectionBindingFlags__SystemReflectionBinder__OBJECT__SZARRAY_OBJECT,
Library_corlib_native_System_Type::GetConstructor___SystemReflectionConstructorInfo__SZARRAY_SystemType,
Library_corlib_native_System_Type::GetConstructors___SZARRAY_SystemReflectionConstructorInfo,
Expand All @@ -86,6 +88,8 @@ static const CLR_RT_MethodHandler method_lookup[] =
Library_corlib_native_System_Type::get_IsEnum___BOOLEAN,
Library_corlib_native_System_Type::get_IsSerializable___BOOLEAN,
Library_corlib_native_System_Type::get_IsArray___BOOLEAN,
Library_corlib_native_System_Type::get_IsGenericType___BOOLEAN,
Library_corlib_native_System_Type::get_IsGenericTypeDefinition___BOOLEAN,
nullptr,
nullptr,
Library_corlib_native_System_Type::GetTypeInternal___STATIC__SystemType__STRING__STRING__BOOLEAN__SZARRAY_I4,
Expand Down Expand Up @@ -255,6 +259,7 @@ static const CLR_RT_MethodHandler method_lookup[] =
nullptr,
nullptr,
nullptr,
nullptr,
Library_corlib_native_System_Array::TrySzIndexOf___STATIC__BOOLEAN__SystemArray__I4__I4__OBJECT__BYREF_I4,
nullptr,
nullptr,
Expand All @@ -269,6 +274,10 @@ static const CLR_RT_MethodHandler method_lookup[] =
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
Library_corlib_native_System_BitConverter::get_IsLittleEndian___STATIC__BOOLEAN,
Library_corlib_native_System_BitConverter::DoubleToInt64Bits___STATIC__I8__R8,
Library_corlib_native_System_BitConverter::GetBytes___STATIC__SZARRAY_U1__BOOLEAN,
Expand Down Expand Up @@ -524,6 +533,7 @@ static const CLR_RT_MethodHandler method_lookup[] =
Library_corlib_native_System_Reflection_Assembly::LoadInternal___STATIC__SystemReflectionAssembly__STRING__BOOLEAN__I4__I4__I4__I4,
Library_corlib_native_System_Reflection_Assembly::Load___STATIC__SystemReflectionAssembly__SZARRAY_U1,
nullptr,
nullptr,
Library_corlib_native_System_Enum::HasFlag___BOOLEAN__SystemEnum,
nullptr,
nullptr,
Expand Down Expand Up @@ -625,6 +635,18 @@ static const CLR_RT_MethodHandler method_lookup[] =
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
Library_corlib_native_System_Number::FormatNative___STATIC__STRING__OBJECT__BOOLEAN__STRING__STRING__STRING__STRING__SZARRAY_I4,
nullptr,
nullptr,
Expand All @@ -645,6 +667,16 @@ static const CLR_RT_MethodHandler method_lookup[] =
nullptr,
nullptr,
nullptr,
Library_corlib_native_System_ReadOnlySpan_1::NativeReadOnlySpanConstructor___VOID__SZARRAY_GENERICTYPE__I4__I4,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
Library_corlib_native_System_Reflection_ConstructorInfo::GetCustomAttributes___SZARRAY_OBJECT__BOOLEAN,
Library_corlib_native_System_Reflection_ConstructorInfo::Invoke___OBJECT__SZARRAY_OBJECT,
nullptr,
Expand Down Expand Up @@ -691,10 +723,12 @@ static const CLR_RT_MethodHandler method_lookup[] =
nullptr,
nullptr,
nullptr,
nullptr,
Library_corlib_native_System_Runtime_CompilerServices_RuntimeHelpers::InitializeArray___STATIC__VOID__SystemArray__SystemRuntimeFieldHandle,
Library_corlib_native_System_Runtime_CompilerServices_RuntimeHelpers::GetObjectValue___STATIC__OBJECT__OBJECT,
Library_corlib_native_System_Runtime_CompilerServices_RuntimeHelpers::RunClassConstructor___STATIC__VOID__SystemRuntimeTypeHandle,
Library_corlib_native_System_Runtime_CompilerServices_RuntimeHelpers::get_OffsetToStringData___STATIC__I4,
nullptr,
Library_corlib_native_System_Runtime_Remoting_RemotingServices::IsTransparentProxy___STATIC__BOOLEAN__OBJECT,
nullptr,
nullptr,
Expand Down Expand Up @@ -734,6 +768,13 @@ static const CLR_RT_MethodHandler method_lookup[] =
nullptr,
nullptr,
nullptr,
Library_corlib_native_System_Span_1::CopyTo___VOID__SystemSpan_1,
nullptr,
nullptr,
nullptr,
Library_corlib_native_System_Span_1::NativeSpanConstructor___VOID__SZARRAY_GENERICTYPE__I4__I4,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
Expand Down Expand Up @@ -1507,7 +1548,7 @@ const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_mscorlib =

#if (NANOCLR_REFLECTION == TRUE)

0x50BF350D,
0x17B85422,

#elif (NANOCLR_REFLECTION == FALSE)

Expand Down
45 changes: 45 additions & 0 deletions src/CLR/CorLib/corlib_native.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ struct Library_corlib_native_System_Reflection_FieldInfo
struct Library_corlib_native_System_Type
{
NANOCLR_NATIVE_DECLARE(get_DeclaringType___SystemType);
NANOCLR_NATIVE_DECLARE(GetGenericTypeDefinition___SystemType);
NANOCLR_NATIVE_DECLARE(GetMethod___SystemReflectionMethodInfo__STRING__SystemReflectionBindingFlags);
NANOCLR_NATIVE_DECLARE(IsInstanceOfType___BOOLEAN__OBJECT);
NANOCLR_NATIVE_DECLARE(GetGenericArguments___SZARRAY_SystemType);
NANOCLR_NATIVE_DECLARE(
InvokeMember___OBJECT__STRING__SystemReflectionBindingFlags__SystemReflectionBinder__OBJECT__SZARRAY_OBJECT);
NANOCLR_NATIVE_DECLARE(GetConstructor___SystemReflectionConstructorInfo__SZARRAY_SystemType);
Expand All @@ -108,6 +110,8 @@ struct Library_corlib_native_System_Type
NANOCLR_NATIVE_DECLARE(get_IsEnum___BOOLEAN);
NANOCLR_NATIVE_DECLARE(get_IsSerializable___BOOLEAN);
NANOCLR_NATIVE_DECLARE(get_IsArray___BOOLEAN);
NANOCLR_NATIVE_DECLARE(get_IsGenericType___BOOLEAN);
NANOCLR_NATIVE_DECLARE(get_IsGenericTypeDefinition___BOOLEAN);
NANOCLR_NATIVE_DECLARE(GetTypeInternal___STATIC__SystemType__STRING__STRING__BOOLEAN__SZARRAY_I4);
NANOCLR_NATIVE_DECLARE(GetTypeFromHandle___STATIC__SystemType__SystemRuntimeTypeHandle);

Expand Down Expand Up @@ -697,6 +701,14 @@ struct Library_corlib_native_System_MulticastDelegate
//--//
};

struct Library_corlib_native_System_Nullable_1
{
static const int FIELD__hasValue = 1;
static const int FIELD__value = 2;

//--//
};

struct Library_corlib_native_System_Number
{
NANOCLR_NATIVE_DECLARE(FormatNative___STATIC__STRING__OBJECT__BOOLEAN__STRING__STRING__STRING__STRING__SZARRAY_I4);
Expand Down Expand Up @@ -764,6 +776,20 @@ struct Library_corlib_native_System_Random
static HRESULT GetRandom(CLR_RT_StackFrame &stack, CLR_RT_Random *&rand, bool create = false);
};

#if (NANOCLR_REFLECTION == TRUE)

struct Library_corlib_native_System_ReadOnlySpan_1
{
static const int FIELD___array = 1;
static const int FIELD___length = 2;

NANOCLR_NATIVE_DECLARE(NativeReadOnlySpanConstructor___VOID__SZARRAY_GENERICTYPE__I4__I4);

//--//
};

#endif // NANOCLR_REFLECTION

struct Library_corlib_native_System_Reflection_AssemblyName
{
static const int FIELD___assembly = 1;
Expand Down Expand Up @@ -910,6 +936,23 @@ struct Library_corlib_native_System_Single
//--//
};

#if (NANOCLR_REFLECTION == TRUE)

struct Library_corlib_native_System_Span_1
{
static const int FIELD___array = 1;
static const int FIELD___length = 2;

NANOCLR_NATIVE_DECLARE(CopyTo___VOID__SystemSpan_1);
NANOCLR_NATIVE_DECLARE(NativeSpanConstructor___VOID__SZARRAY_GENERICTYPE__I4__I4);

//--//
};

#endif // NANOCLR_REFLECTION

#if (NANOCLR_REFLECTION != TRUE)

struct Library_corlib_native_System_SpanByte
{
static const int FIELD___array = 1;
Expand All @@ -919,6 +962,8 @@ struct Library_corlib_native_System_SpanByte
//--//
};

#endif // NANOCLR_REFLECTION

struct Library_corlib_native_System_Threading_AutoResetEvent
{
NANOCLR_NATIVE_DECLARE(_ctor___VOID__BOOLEAN);
Expand Down
52 changes: 52 additions & 0 deletions src/CLR/CorLib/corlib_native_System_ReadOnlySpan_1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// Copyright (c) .NET Foundation and Contributors
// Portions Copyright (c) Microsoft Corporation. All rights reserved.
// See LICENSE file in the project root for full license information.
//

#include "CorLib.h"

HRESULT Library_corlib_native_System_ReadOnlySpan_1::NativeReadOnlySpanConstructor___VOID__SZARRAY_GENERICTYPE__I4__I4(
CLR_RT_StackFrame &stack)
{
NANOCLR_HEADER();

int32_t start;
int32_t length;

CLR_RT_TypeDescriptor descDst{};
CLR_RT_TypeDef_Index sourceType{};
CLR_RT_HeapBlock_Array *destinationArray;
CLR_RT_HeapBlock_Array *sourceArray = stack.Arg1().DereferenceArray();
CLR_RT_HeapBlock *thisSpan = stack.This();

// get working values
start = stack.Arg2().NumericByRefConst().s4;
length = stack.Arg3().NumericByRefConst().s4;

{
// get type of the source array
NANOCLR_CHECK_HRESULT(descDst.InitializeFromObject(*sourceArray));
descDst.GetElementType(descDst);

sourceType.data = descDst.m_handlerCls.data;

CLR_RT_HeapBlock &refArray = thisSpan[FIELD___array];
CLR_RT_HeapBlock_Array::CreateInstance(refArray, length, sourceType);

// get pointer to the array
destinationArray = thisSpan[FIELD___array].DereferenceArray();

// protect from GC
CLR_RT_ProtectFromGC gc1(*sourceArray);
CLR_RT_ProtectFromGC gc2(refArray);

// copy array
CLR_RT_HeapBlock_Array::Copy(sourceArray, start, destinationArray, 0, length);

// set length
thisSpan[FIELD___length].NumericByRef().s4 = length;
}

NANOCLR_NOCLEANUP();
}
Loading