Guo Hui пре 6 година
родитељ
комит
0e2c27402a
100 измењених фајлова са 1386 додато и 423 уклоњено
  1. 32 16
      Natsu.sln
  2. 0 1
      cmake/kd233.cmake
  3. 1 0
      src/Chino.Chip.Emulator/Chino.Chip.Emulator.csproj
  4. 21 0
      src/Chino.Core/Threading/Thread.cs
  5. 3 1
      src/Chino.Kernel/Program.cs
  6. 6 0
      src/Chino.Kernel/Threading/ThreadManager.cs
  7. 5 2
      src/Native/CMakeLists.txt
  8. 2 1
      src/Native/arch/riscv64/CMakeLists.txt
  9. 1 1
      src/Native/arch/riscv64/crt.cpp
  10. 0 0
      src/Native/arch/riscv64/dummy.cpp
  11. 8 8
      src/Native/chino.runtime.h
  12. 74 74
      src/Native/natsu.fcall.cpp
  13. 6 6
      src/Native/natsu.gc.cpp
  14. 18 11
      src/Native/natsu.runtime.cpp
  15. 141 176
      src/Native/natsu.runtime.h
  16. 10 10
      src/Native/natsu.threading.cpp
  17. 106 17
      src/Native/natsu.typedef.h
  18. 8 8
      src/Native/natsu.unicode.cpp
  19. 18 11
      src/Natsu.Compiler/ILImporter.cs
  20. 58 45
      src/Natsu.Compiler/Program.cs
  21. 88 23
      src/Natsu.Compiler/TypeUtils.cs
  22. 3 2
      src/ResX2CS/Program.cs
  23. 1 2
      src/ResX2CS/ResX2CS.csproj
  24. 34 0
      src/System.Collections/ICollectionDebugView.cs
  25. 515 0
      src/System.Collections/LinkedList.cs
  26. 42 0
      src/System.Collections/Resources/Strings.Designer.cs
  27. 169 0
      src/System.Collections/Resources/Strings.resx
  28. 8 1
      src/System.Collections/System.Collections.csproj
  29. 1 1
      src/System.Collections/TypeForwards.cs
  30. 1 1
      src/System.Diagnostics.Debug/System.Diagnostics.Debug.csproj
  31. 1 1
      src/System.Memory/System.Memory.csproj
  32. 0 3
      src/System.Private.CorLib/Properties/AssemblyInfo.cs
  33. 0 0
      src/System.Private.CoreLib/Internal/System/Runtime/CompilerServices/Unsafe.cs
  34. 0 0
      src/System.Private.CoreLib/Natsu/AssemblyEmbeddedCodeAttribute.cs
  35. 4 0
      src/System.Private.CoreLib/Properties/AssemblyInfo.cs
  36. 0 0
      src/System.Private.CoreLib/Resources/Strings.Designer.cs
  37. 0 0
      src/System.Private.CoreLib/Resources/Strings.resx
  38. 1 1
      src/System.Private.CoreLib/System.Private.CoreLib.csproj
  39. 0 0
      src/System.Private.CoreLib/System.Private.CoreLib.csproj.user
  40. 0 0
      src/System.Private.CoreLib/System/Action.cs
  41. 0 0
      src/System.Private.CoreLib/System/ArgumentException.cs
  42. 0 0
      src/System.Private.CoreLib/System/ArgumentNullException.cs
  43. 0 0
      src/System.Private.CoreLib/System/ArgumentOutOfRangeException.cs
  44. 0 0
      src/System.Private.CoreLib/System/ArithmeticException.cs
  45. 0 0
      src/System.Private.CoreLib/System/Array.cs
  46. 0 0
      src/System.Private.CoreLib/System/ArraySegment.cs
  47. 0 0
      src/System.Private.CoreLib/System/ArrayTypeMismatchException.cs
  48. 0 0
      src/System.Private.CoreLib/System/Attribute.cs
  49. 0 0
      src/System.Private.CoreLib/System/AttributeTargets.cs
  50. 0 0
      src/System.Private.CoreLib/System/AttributeUsageAttribute.cs
  51. 0 0
      src/System.Private.CoreLib/System/BitConverter.cs
  52. 0 0
      src/System.Private.CoreLib/System/Boolean.cs
  53. 0 0
      src/System.Private.CoreLib/System/Buffer.cs
  54. 0 0
      src/System.Private.CoreLib/System/Buffers/IMemoryOwner.cs
  55. 0 0
      src/System.Private.CoreLib/System/Buffers/MemoryManager.cs
  56. 0 0
      src/System.Private.CoreLib/System/Buffers/Text/FormattingHelpers.CountDigits.cs
  57. 0 0
      src/System.Private.CoreLib/System/ByReference.cs
  58. 0 0
      src/System.Private.CoreLib/System/Byte.cs
  59. 0 0
      src/System.Private.CoreLib/System/CLSCompliantAttribute.cs
  60. 0 0
      src/System.Private.CoreLib/System/Char.cs
  61. 0 0
      src/System.Private.CoreLib/System/CharEnumerator.cs
  62. 0 0
      src/System.Private.CoreLib/System/Collections/Comparer.cs
  63. 0 0
      src/System.Private.CoreLib/System/Collections/Generic/ArraySortHelper.NatsuCLR.cs
  64. 0 0
      src/System.Private.CoreLib/System/Collections/Generic/ArraySortHelper.cs
  65. 0 0
      src/System.Private.CoreLib/System/Collections/Generic/Comparer.NatsuCLR.cs
  66. 0 0
      src/System.Private.CoreLib/System/Collections/Generic/Comparer.cs
  67. 0 0
      src/System.Private.CoreLib/System/Collections/Generic/ComparerHelpers.cs
  68. 0 0
      src/System.Private.CoreLib/System/Collections/Generic/EqualityComparer.NatsuCLR.cs
  69. 0 0
      src/System.Private.CoreLib/System/Collections/Generic/EqualityComparer.cs
  70. 0 0
      src/System.Private.CoreLib/System/Collections/Generic/ICollection.cs
  71. 0 0
      src/System.Private.CoreLib/System/Collections/Generic/ICollectionDebugView.cs
  72. 0 0
      src/System.Private.CoreLib/System/Collections/Generic/IComparer.cs
  73. 0 0
      src/System.Private.CoreLib/System/Collections/Generic/IEnumerable.cs
  74. 0 0
      src/System.Private.CoreLib/System/Collections/Generic/IEnumerator.cs
  75. 0 0
      src/System.Private.CoreLib/System/Collections/Generic/IEqualityComparer.cs
  76. 0 0
      src/System.Private.CoreLib/System/Collections/Generic/IList.cs
  77. 0 0
      src/System.Private.CoreLib/System/Collections/Generic/IReadOnlyCollection.cs
  78. 0 0
      src/System.Private.CoreLib/System/Collections/Generic/IReadOnlyList.cs
  79. 0 0
      src/System.Private.CoreLib/System/Collections/Generic/KeyNotFoundException.cs
  80. 0 0
      src/System.Private.CoreLib/System/Collections/Generic/List.cs
  81. 0 0
      src/System.Private.CoreLib/System/Collections/IComparer.cs
  82. 0 0
      src/System.Private.CoreLib/System/Collections/IEqualityComparer.cs
  83. 0 0
      src/System.Private.CoreLib/System/Collections/IStructuralComparable.cs
  84. 0 0
      src/System.Private.CoreLib/System/Collections/IStructuralEquatable.cs
  85. 0 0
      src/System.Private.CoreLib/System/ComponentModel/EditorBrowsableAttribute.cs
  86. 0 0
      src/System.Private.CoreLib/System/Console.cs
  87. 0 0
      src/System.Private.CoreLib/System/Delegate.cs
  88. 0 0
      src/System.Private.CoreLib/System/Diagnostics/CodeAnalysis/NullableAttributes.cs
  89. 0 0
      src/System.Private.CoreLib/System/Diagnostics/CodeAnalysis/SuppressMessageAttribute.cs
  90. 0 0
      src/System.Private.CoreLib/System/Diagnostics/ConditionalAttribute.cs
  91. 0 0
      src/System.Private.CoreLib/System/Diagnostics/Debug.cs
  92. 0 0
      src/System.Private.CoreLib/System/Diagnostics/DebuggerBrowsableAttribute.cs
  93. 0 0
      src/System.Private.CoreLib/System/Diagnostics/DebuggerDisplayAttribute.cs
  94. 0 0
      src/System.Private.CoreLib/System/Diagnostics/DebuggerHiddenAttribute.cs
  95. 0 0
      src/System.Private.CoreLib/System/Diagnostics/DebuggerNonUserCodeAttribute.cs
  96. 0 0
      src/System.Private.CoreLib/System/Diagnostics/DebuggerTypeProxyAttribute.cs
  97. 0 0
      src/System.Private.CoreLib/System/Diagnostics/StackTraceHiddenAttribute.cs
  98. 0 0
      src/System.Private.CoreLib/System/Double.cs
  99. 0 0
      src/System.Private.CoreLib/System/Enum.cs
  100. 0 0
      src/System.Private.CoreLib/System/Environment.cs

+ 32 - 16
Natsu.sln

@@ -5,12 +5,13 @@ VisualStudioVersion = 16.0.29021.104
 MinimumVisualStudioVersion = 10.0.40219.1
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Natsu.Compiler", "src\Natsu.Compiler\Natsu.Compiler.csproj", "{AC6248DB-5117-4C47-A3E7-D0B7E6258F6B}"
 	ProjectSection(ProjectDependencies) = postProject
-		{CE15C733-B010-41FD-B1B6-D0D4327F0653} = {CE15C733-B010-41FD-B1B6-D0D4327F0653}
+		{54C1C11C-300D-4CEC-AE9D-E669C2B2D6C7} = {54C1C11C-300D-4CEC-AE9D-E669C2B2D6C7}
 		{A4CE4A60-2E56-4712-901B-8E5FA1354FD6} = {A4CE4A60-2E56-4712-901B-8E5FA1354FD6}
 		{9D224463-2FCE-4C20-B036-7600FC66969A} = {9D224463-2FCE-4C20-B036-7600FC66969A}
 		{20176878-F31F-4D92-918C-9FD58CDD7480} = {20176878-F31F-4D92-918C-9FD58CDD7480}
 		{7374FA7F-5B76-40C8-8F8F-EB9CA53A8C2F} = {7374FA7F-5B76-40C8-8F8F-EB9CA53A8C2F}
 		{C4408589-968A-43B3-83A6-AF02D1BAA293} = {C4408589-968A-43B3-83A6-AF02D1BAA293}
+		{8309558E-335D-4662-B56B-11AFD5E1C1C3} = {8309558E-335D-4662-B56B-11AFD5E1C1C3}
 		{357BCAA3-32A6-41E3-A616-57CE73470C1B} = {357BCAA3-32A6-41E3-A616-57CE73470C1B}
 		{FE1EA2B2-2DF7-4570-9710-AF31D00DF2F6} = {FE1EA2B2-2DF7-4570-9710-AF31D00DF2F6}
 		{2C03C9E9-3EE6-4F74-8BF7-C9040E9E4A14} = {2C03C9E9-3EE6-4F74-8BF7-C9040E9E4A14}
@@ -19,8 +20,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Natsu.Compiler", "src\Natsu
 		{E7F325FF-7C85-4C64-8E96-E06AE3A5238D} = {E7F325FF-7C85-4C64-8E96-E06AE3A5238D}
 	EndProjectSection
 EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Private.CorLib", "src\System.Private.CorLib\System.Private.CorLib.csproj", "{CE15C733-B010-41FD-B1B6-D0D4327F0653}"
-EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Chino.Kernel", "src\Chino.Kernel\Chino.Kernel.csproj", "{7374FA7F-5B76-40C8-8F8F-EB9CA53A8C2F}"
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Runtime", "src\System.Runtime\System.Runtime.csproj", "{A4CE4A60-2E56-4712-901B-8E5FA1354FD6}"
@@ -51,6 +50,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Memory", "src\System
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Collections", "src\System.Collections\System.Collections.csproj", "{9D224463-2FCE-4C20-B036-7600FC66969A}"
 EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Threading.Thread", "src\System.Threading.Thread\System.Threading.Thread.csproj", "{54C1C11C-300D-4CEC-AE9D-E669C2B2D6C7}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Private.CoreLib", "src\System.Private.CoreLib\System.Private.CoreLib.csproj", "{8309558E-335D-4662-B56B-11AFD5E1C1C3}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -73,18 +76,6 @@ Global
 		{AC6248DB-5117-4C47-A3E7-D0B7E6258F6B}.Release|Emulator.Build.0 = Release|Any CPU
 		{AC6248DB-5117-4C47-A3E7-D0B7E6258F6B}.Release|KD233.ActiveCfg = Release|Any CPU
 		{AC6248DB-5117-4C47-A3E7-D0B7E6258F6B}.Release|KD233.Build.0 = Release|Any CPU
-		{CE15C733-B010-41FD-B1B6-D0D4327F0653}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{CE15C733-B010-41FD-B1B6-D0D4327F0653}.Debug|Any CPU.Build.0 = Debug|Any CPU
-		{CE15C733-B010-41FD-B1B6-D0D4327F0653}.Debug|Emulator.ActiveCfg = Debug|Any CPU
-		{CE15C733-B010-41FD-B1B6-D0D4327F0653}.Debug|Emulator.Build.0 = Debug|Any CPU
-		{CE15C733-B010-41FD-B1B6-D0D4327F0653}.Debug|KD233.ActiveCfg = Debug|Any CPU
-		{CE15C733-B010-41FD-B1B6-D0D4327F0653}.Debug|KD233.Build.0 = Debug|Any CPU
-		{CE15C733-B010-41FD-B1B6-D0D4327F0653}.Release|Any CPU.ActiveCfg = Release|Any CPU
-		{CE15C733-B010-41FD-B1B6-D0D4327F0653}.Release|Any CPU.Build.0 = Release|Any CPU
-		{CE15C733-B010-41FD-B1B6-D0D4327F0653}.Release|Emulator.ActiveCfg = Release|Any CPU
-		{CE15C733-B010-41FD-B1B6-D0D4327F0653}.Release|Emulator.Build.0 = Release|Any CPU
-		{CE15C733-B010-41FD-B1B6-D0D4327F0653}.Release|KD233.ActiveCfg = Release|Any CPU
-		{CE15C733-B010-41FD-B1B6-D0D4327F0653}.Release|KD233.Build.0 = Release|Any CPU
 		{7374FA7F-5B76-40C8-8F8F-EB9CA53A8C2F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 		{7374FA7F-5B76-40C8-8F8F-EB9CA53A8C2F}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{7374FA7F-5B76-40C8-8F8F-EB9CA53A8C2F}.Debug|Emulator.ActiveCfg = Debug|Emulator
@@ -241,13 +232,36 @@ Global
 		{9D224463-2FCE-4C20-B036-7600FC66969A}.Release|Emulator.Build.0 = Release|Any CPU
 		{9D224463-2FCE-4C20-B036-7600FC66969A}.Release|KD233.ActiveCfg = Release|Any CPU
 		{9D224463-2FCE-4C20-B036-7600FC66969A}.Release|KD233.Build.0 = Release|Any CPU
+		{54C1C11C-300D-4CEC-AE9D-E669C2B2D6C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{54C1C11C-300D-4CEC-AE9D-E669C2B2D6C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{54C1C11C-300D-4CEC-AE9D-E669C2B2D6C7}.Debug|Emulator.ActiveCfg = Debug|Any CPU
+		{54C1C11C-300D-4CEC-AE9D-E669C2B2D6C7}.Debug|Emulator.Build.0 = Debug|Any CPU
+		{54C1C11C-300D-4CEC-AE9D-E669C2B2D6C7}.Debug|KD233.ActiveCfg = Debug|Any CPU
+		{54C1C11C-300D-4CEC-AE9D-E669C2B2D6C7}.Debug|KD233.Build.0 = Debug|Any CPU
+		{54C1C11C-300D-4CEC-AE9D-E669C2B2D6C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{54C1C11C-300D-4CEC-AE9D-E669C2B2D6C7}.Release|Any CPU.Build.0 = Release|Any CPU
+		{54C1C11C-300D-4CEC-AE9D-E669C2B2D6C7}.Release|Emulator.ActiveCfg = Release|Any CPU
+		{54C1C11C-300D-4CEC-AE9D-E669C2B2D6C7}.Release|Emulator.Build.0 = Release|Any CPU
+		{54C1C11C-300D-4CEC-AE9D-E669C2B2D6C7}.Release|KD233.ActiveCfg = Release|Any CPU
+		{54C1C11C-300D-4CEC-AE9D-E669C2B2D6C7}.Release|KD233.Build.0 = Release|Any CPU
+		{8309558E-335D-4662-B56B-11AFD5E1C1C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{8309558E-335D-4662-B56B-11AFD5E1C1C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{8309558E-335D-4662-B56B-11AFD5E1C1C3}.Debug|Emulator.ActiveCfg = Debug|Any CPU
+		{8309558E-335D-4662-B56B-11AFD5E1C1C3}.Debug|Emulator.Build.0 = Debug|Any CPU
+		{8309558E-335D-4662-B56B-11AFD5E1C1C3}.Debug|KD233.ActiveCfg = Debug|Any CPU
+		{8309558E-335D-4662-B56B-11AFD5E1C1C3}.Debug|KD233.Build.0 = Debug|Any CPU
+		{8309558E-335D-4662-B56B-11AFD5E1C1C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{8309558E-335D-4662-B56B-11AFD5E1C1C3}.Release|Any CPU.Build.0 = Release|Any CPU
+		{8309558E-335D-4662-B56B-11AFD5E1C1C3}.Release|Emulator.ActiveCfg = Release|Any CPU
+		{8309558E-335D-4662-B56B-11AFD5E1C1C3}.Release|Emulator.Build.0 = Release|Any CPU
+		{8309558E-335D-4662-B56B-11AFD5E1C1C3}.Release|KD233.ActiveCfg = Release|Any CPU
+		{8309558E-335D-4662-B56B-11AFD5E1C1C3}.Release|KD233.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
 	EndGlobalSection
 	GlobalSection(NestedProjects) = preSolution
 		{AC6248DB-5117-4C47-A3E7-D0B7E6258F6B} = {898F8F18-37B6-4D6C-927D-08F1FBC2672C}
-		{CE15C733-B010-41FD-B1B6-D0D4327F0653} = {898F8F18-37B6-4D6C-927D-08F1FBC2672C}
 		{7374FA7F-5B76-40C8-8F8F-EB9CA53A8C2F} = {898F8F18-37B6-4D6C-927D-08F1FBC2672C}
 		{A4CE4A60-2E56-4712-901B-8E5FA1354FD6} = {898F8F18-37B6-4D6C-927D-08F1FBC2672C}
 		{2C03C9E9-3EE6-4F74-8BF7-C9040E9E4A14} = {898F8F18-37B6-4D6C-927D-08F1FBC2672C}
@@ -261,6 +275,8 @@ Global
 		{CF7D1BFB-188E-452A-B806-5BCAEBF42400} = {898F8F18-37B6-4D6C-927D-08F1FBC2672C}
 		{357BCAA3-32A6-41E3-A616-57CE73470C1B} = {898F8F18-37B6-4D6C-927D-08F1FBC2672C}
 		{9D224463-2FCE-4C20-B036-7600FC66969A} = {898F8F18-37B6-4D6C-927D-08F1FBC2672C}
+		{54C1C11C-300D-4CEC-AE9D-E669C2B2D6C7} = {898F8F18-37B6-4D6C-927D-08F1FBC2672C}
+		{8309558E-335D-4662-B56B-11AFD5E1C1C3} = {898F8F18-37B6-4D6C-927D-08F1FBC2672C}
 	EndGlobalSection
 	GlobalSection(ExtensibilityGlobals) = postSolution
 		SolutionGuid = {429BE0BD-F176-4959-97F3-6F657A877050}

+ 0 - 1
cmake/kd233.cmake

@@ -21,7 +21,6 @@ add_compile_options(
     -std=c++17
     -ffast-math
     -Os
-    -flto
     -ffunction-sections
     -fdata-sections
     -mcmodel=medany

+ 1 - 0
src/Chino.Chip.Emulator/Chino.Chip.Emulator.csproj

@@ -2,6 +2,7 @@
 
   <PropertyGroup>
     <TargetFramework>netcoreapp3.0</TargetFramework>
+    <OutputPath>$(SolutionDir)out/bin/</OutputPath>
   </PropertyGroup>
 
   <ItemGroup>

+ 21 - 0
src/Chino.Core/Threading/Thread.cs

@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using ThreadStart = System.Threading.ThreadStart;
+
+namespace Chino.Threading
+{
+    public class Thread
+    {
+        private readonly ThreadStart _start;
+
+        public Thread(ThreadStart start)
+        {
+            _start = start;
+        }
+
+        public void Start(object? arg)
+        {
+        }
+    }
+}

+ 3 - 1
src/Chino.Kernel/Program.cs

@@ -11,7 +11,7 @@ namespace Chino.Kernel
         {
             ChipControl.Initialize();
 
-            var terminal = new Terminal();
+            var terminal = Terminal.Default;
 
             terminal.Foreground(TerminalColor.White)
                 .WriteLine("Hello Chino OS!");
@@ -48,6 +48,8 @@ namespace Chino.Kernel
 
     class Terminal
     {
+        public static Terminal Default { get; } = new Terminal();
+
         public Terminal Write(string message)
         {
             Debug.Write(message);

+ 6 - 0
src/Chino.Kernel/Threading/ThreadManager.cs

@@ -1,8 +1,14 @@
 using System;
+using System.Collections.Generic;
 
 namespace Chino.Threading
 {
     public class ThreadManager
     {
+        public static ThreadManager Default { get; } = new ThreadManager();
+
+        private readonly LinkedList<Thread> _runningThreads = new LinkedList<Thread>();
+        private readonly LinkedList<Thread> _readyThreads = new LinkedList<Thread>();
+        private readonly LinkedList<Thread> _suspendedThreads = new LinkedList<Thread>();
     }
 }

+ 5 - 2
src/Native/CMakeLists.txt

@@ -10,7 +10,8 @@ set(SRCS natsu.fcall.cpp
          natsu.unicode.cpp
          natsu.threading.cpp
          main.cpp
-         Generated/System.Private.CorLib.cpp
+         Generated/System.Private.CoreLib.cpp
+         Generated/System.Collections.cpp
          Generated/System.Diagnostics.Debug.cpp
          Generated/System.Runtime.cpp
          Generated/Chino.Core.cpp
@@ -21,7 +22,9 @@ add_executable(chino ${SRCS} ${ASM_SRCS})
 target_link_libraries(chino PUBLIC arch)
 
 if (NOT WIN32)
-    target_link_libraries(chino -Wl,-gc-sections -Wl,-static -T ${CMAKE_CURRENT_LIST_DIR}/board/${CHINO_ARCH}/${CHINO_BOARD}/chino.ld)
+    target_link_libraries(chino PRIVATE -Wl,-gc-sections -Wl,-static -T ${CMAKE_CURRENT_LIST_DIR}/board/${CHINO_ARCH}/${CHINO_BOARD}/chino.ld)
+    target_link_libraries(chino PRIVATE stdc++ arch)
+    target_compile_options(chino PRIVATE -flto)
 endif()
 
 ADD_CUSTOM_COMMAND(OUTPUT chino.bin

+ 2 - 1
src/Native/arch/riscv64/CMakeLists.txt

@@ -1,5 +1,6 @@
 set(ASM_SRCS crt.S)
-set(SRCS crt.cpp)
+set(SRCS crt.cpp
+         ${GENERATED_DIR}/Chino.Chip.K210.cpp)
 
 set_property(SOURCE ${ASM_SRCS} PROPERTY LANGUAGE C)
 add_library(arch STATIC ${SRCS} ${ASM_SRCS})

+ 1 - 1
src/Native/arch/riscv64/crt.cpp

@@ -172,6 +172,6 @@ extern "C"
 
 namespace __cxxabiv1
 {
-std::terminate_handler __terminate_handler = abort;
+//std::terminate_handler __terminate_handler = abort;
 }
 #endif

+ 0 - 0
src/Native/arch/riscv64/dummy.cpp


+ 8 - 8
src/Native/chino.runtime.h

@@ -1,20 +1,20 @@
 // chino os runtime
 #pragma once
-#include "Generated/System.Private.CorLib.h"
+#include "Generated/System.Private.CoreLib.h"
 
 namespace Chino_Core
 {
 template <class T>
-::natsu::gc_ref<::natsu::variable_type_t<T>> Chino::IOVolatile::_s_As(::System_Runtime::System::UInt32 address)
+::natsu::gc_ref<::natsu::variable_type_t<T>> Chino::IOVolatile::_s_As(uint32_t address)
 {
-    return ::natsu::gc_ref<::natsu::variable_type_t<T>>((uintptr_t)address.m_value);
+    return ::natsu::gc_ref_from_addr<::natsu::variable_type_t<T>>((uintptr_t)address);
 }
 
 template <class T>
 ::natsu::variable_type_t<T> Chino::IOVolatile::_s_Read(::natsu::gc_ref<::natsu::variable_type_t<T>> address)
 {
-    using elem_t = std::decay_t<decltype(address->Value.m_value)>;
-    auto value = *reinterpret_cast<const volatile elem_t *>(&address->Value.m_value);
+    using elem_t = std::decay_t<decltype(address->Value)>;
+    auto value = *reinterpret_cast<const volatile elem_t *>(&address->Value);
     T result;
     result.Value = value;
     return result;
@@ -23,8 +23,8 @@ template <class T>
 template <class T>
 void Chino::IOVolatile::_s_Write(::natsu::gc_ref<::natsu::variable_type_t<T>> address, ::natsu::variable_type_t<T> value)
 {
-    using elem_t = std::decay_t<decltype(address->Value.m_value)>;
-    auto ptr = reinterpret_cast<volatile elem_t *>(&address->Value.m_value);
-    *ptr = value.Value.m_value;
+    using elem_t = std::decay_t<decltype(address->Value)>;
+    auto ptr = reinterpret_cast<volatile elem_t *>(&address->Value);
+    *ptr = value.Value;
 }
 }

+ 74 - 74
src/Native/natsu.fcall.cpp

@@ -3,61 +3,61 @@
 #include <cstring>
 
 using namespace natsu;
-using namespace System_Private_CorLib;
-using namespace System_Private_CorLib::System;
-using namespace System_Private_CorLib::System::Diagnostics;
-using namespace System_Private_CorLib::System::Runtime;
-using namespace System_Private_CorLib::System::Runtime::CompilerServices;
+using namespace System_Private_CoreLib;
+using namespace System_Private_CoreLib::System;
+using namespace System_Private_CoreLib::System::Diagnostics;
+using namespace System_Private_CoreLib::System::Runtime;
+using namespace System_Private_CoreLib::System::Runtime::CompilerServices;
 
-Int32 Array::GetLength(gc_obj_ref<Array> _this, Int32 dimension)
+int32_t Array::GetLength(gc_obj_ref<Array> _this, int32_t dimension)
 {
     if (dimension != 0)
         throw_exception<IndexOutOfRangeException>();
     return (intptr_t)_this.cast<RawSzArrayData>()->Count;
 }
 
-Int32 Array::get_Rank(gc_obj_ref<Array> _this)
+int32_t Array::get_Rank(gc_obj_ref<Array> _this)
 {
     return 1;
 }
 
-Int32 Array::get_Length(gc_obj_ref<Array> _this)
+int32_t Array::get_Length(gc_obj_ref<Array> _this)
 {
     return (intptr_t)_this.cast<RawSzArrayData>()->Count;
 }
 
-Int64 Array::get_LongLength(gc_obj_ref<Array> _this)
+int64_t Array::get_LongLength(gc_obj_ref<Array> _this)
 {
     return (intptr_t)_this.cast<RawSzArrayData>()->Count;
 }
 
-Int32 Array::GetUpperBound(gc_obj_ref<Array> _this, Int32 dimension)
+int32_t Array::GetUpperBound(gc_obj_ref<Array> _this, int32_t dimension)
 {
     return GetLength(_this, dimension);
 }
 
-Int32 Array::GetLowerBound(gc_obj_ref<Array> _this, Int32 dimension)
+int32_t Array::GetLowerBound(gc_obj_ref<Array> _this, int32_t dimension)
 {
     if (dimension != 0)
         throw_exception<IndexOutOfRangeException>();
     return 0;
 }
 
-void Array::_s_Copy(gc_obj_ref<Array> sourceArray, Int32 sourceIndex, gc_obj_ref<Array> destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
+void Array::_s_Copy(gc_obj_ref<Array> sourceArray, int32_t sourceIndex, gc_obj_ref<Array> destinationArray, int32_t destinationIndex, int32_t length, bool reliable)
 {
     throw_exception<InvalidOperationException>();
 }
 
-gc_ref<Byte> Array::_s_GetRawArrayGeometry(gc_obj_ref<Array> array, gc_ref<UInt32> numComponents, gc_ref<UInt32> elementSize, gc_ref<Int32> lowerBound, ::natsu::gc_ref<Boolean> containsGCPointers)
+gc_ref<uint8_t> Array::_s_GetRawArrayGeometry(gc_obj_ref<Array> array, gc_ref<uint32_t> numComponents, gc_ref<uint32_t> elementSize, gc_ref<int32_t> lowerBound, ::natsu::gc_ref<bool> containsGCPointers)
 {
-    *numComponents = (UInt32)Array::GetLength(array, 0);
+    *numComponents = (uint32_t)Array::GetLength(array, 0);
     *elementSize = array.header().vtable_->ElementSize;
     *lowerBound = Array::GetLowerBound(array, 0);
     *containsGCPointers = true;
     return array.cast<RawSzArrayData>()->Data;
 }
 
-void Buffer::_s_Memcpy(gc_ptr<Byte> dest, gc_ptr<Byte> src, Int32 len)
+void Buffer::_s_Memcpy(gc_ptr<uint8_t> dest, gc_ptr<uint8_t> src, int32_t len)
 {
     std::memcpy(dest, src, len);
 }
@@ -70,7 +70,7 @@ void Debug::_s_WriteCore(gc_obj_ref<String> message)
 void Debug::_s_WriteLineCore(gc_obj_ref<String> message)
 {
     Chino_Kernel::Chino::Kernel::KernelDebug::_s_Write(message);
-    Chino_Kernel::Chino::Kernel::KernelDebug::_s_Write(::System_Private_CorLib::System::Environment::_s_get_NewLine());
+    Chino_Kernel::Chino::Kernel::KernelDebug::_s_Write(::System_Private_CoreLib::System::Environment::_s_get_NewLine());
 }
 
 void Debug::_s_FailCore(gc_obj_ref<String> message, gc_obj_ref<String> detailMessage)
@@ -78,7 +78,7 @@ void Debug::_s_FailCore(gc_obj_ref<String> message, gc_obj_ref<String> detailMes
     Chino_Kernel::Chino::Kernel::KernelDebug::_s_Write(message);
 }
 
-void Buffer::_s_Memmove(gc_ptr<Byte> dest, gc_ptr<Byte> src, UInt64 len)
+void Buffer::_s_Memmove(gc_ptr<uint8_t> dest, gc_ptr<uint8_t> src, uint64_t len)
 {
     std::memmove(dest, src, len);
 }
@@ -89,19 +89,19 @@ gc_obj_ref<Type> Object::GetType(::natsu::gc_obj_ref<Object> _this)
     return ::natsu::null;
 }
 
-Char String::get_Chars(gc_obj_ref<String> _this, Int32 index)
+char16_t String::get_Chars(gc_obj_ref<String> _this, int32_t index)
 {
     if ((uint32_t)index >= (uint32_t)_this->_stringLength)
         throw_exception<IndexOutOfRangeException>();
     return (&_this->_firstChar)[index];
 }
 
-Int32 String::get_Length(gc_obj_ref<String> _this)
+int32_t String::get_Length(gc_obj_ref<String> _this)
 {
     return _this->_stringLength;
 }
 
-gc_obj_ref<String> String::_s_FastAllocateString(Int32 length)
+gc_obj_ref<String> String::_s_FastAllocateString(int32_t length)
 {
     auto size = sizeof(String) + length * sizeof(Char);
     auto obj = natsu::gc_new<String>(size);
@@ -110,135 +110,135 @@ gc_obj_ref<String> String::_s_FastAllocateString(Int32 length)
     return obj;
 }
 
-Int32 String::_s_wcslen(gc_ptr<Char> ptr)
+int32_t String::_s_wcslen(gc_ptr<char16_t> ptr)
 {
-    std::u16string_view sv = reinterpret_cast<const char16_t *>(&ptr->m_value);
+    std::u16string_view sv(ptr);
     return (int32_t)sv.length();
 }
 
-Double Math::_s_Abs(Double value)
+double Math::_s_Abs(double value)
 {
-    return fabs(value.m_value);
+    return fabs(value);
 }
 
-Single Math::_s_Abs(Single value)
+float Math::_s_Abs(float value)
 {
-    return fabsf(value.m_value);
+    return fabsf(value);
 }
 
-Double Math::_s_Acos(Double value)
+double Math::_s_Acos(double value)
 {
-    return acos(value.m_value);
+    return acos(value);
 }
 
-Double Math::_s_Acosh(Double value)
+double Math::_s_Acosh(double value)
 {
-    return acosh(value.m_value);
+    return acosh(value);
 }
 
-Double Math::_s_Asin(Double value)
+double Math::_s_Asin(double value)
 {
-    return asin(value.m_value);
+    return asin(value);
 }
 
-Double Math::_s_Asinh(Double value)
+double Math::_s_Asinh(double value)
 {
-    return asinh(value.m_value);
+    return asinh(value);
 }
 
-Double Math::_s_Atan(Double value)
+double Math::_s_Atan(double value)
 {
-    return atan(value.m_value);
+    return atan(value);
 }
 
-Double Math::_s_Atan2(Double y, Double x)
+double Math::_s_Atan2(double y, double x)
 {
-    return atan2(y.m_value, x.m_value);
+    return atan2(y, x);
 }
 
-Double Math::_s_Atanh(Double value)
+double Math::_s_Atanh(double value)
 {
-    return atanh(value.m_value);
+    return atanh(value);
 }
 
-Double Math::_s_Cbrt(Double value)
+double Math::_s_Cbrt(double value)
 {
-    return cbrt(value.m_value);
+    return cbrt(value);
 }
 
-Double Math::_s_Ceiling(Double value)
+double Math::_s_Ceiling(double value)
 {
-    return ceil(value.m_value);
+    return ceil(value);
 }
 
-Double Math::_s_Cos(Double value)
+double Math::_s_Cos(double value)
 {
-    return cos(value.m_value);
+    return cos(value);
 }
 
-Double Math::_s_Cosh(Double value)
+double Math::_s_Cosh(double value)
 {
-    return cosh(value.m_value);
+    return cosh(value);
 }
 
-Double Math::_s_Exp(Double value)
+double Math::_s_Exp(double value)
 {
-    return exp(value.m_value);
+    return exp(value);
 }
 
-Double Math::_s_Floor(Double value)
+double Math::_s_Floor(double value)
 {
-    return floor(value.m_value);
+    return floor(value);
 }
 
-Double Math::_s_Log(Double value)
+double Math::_s_Log(double value)
 {
-    return log(value.m_value);
+    return log(value);
 }
 
-Double Math::_s_Log10(Double value)
+double Math::_s_Log10(double value)
 {
-    return log10(value.m_value);
+    return log10(value);
 }
 
-Double Math::_s_Pow(Double x, Double y)
+double Math::_s_Pow(double x, double y)
 {
-    return pow(x.m_value, y.m_value);
+    return pow(x, y);
 }
 
-Double Math::_s_Sin(Double value)
+double Math::_s_Sin(double value)
 {
-    return sin(value.m_value);
+    return sin(value);
 }
 
-Double Math::_s_Sinh(Double value)
+double Math::_s_Sinh(double value)
 {
-    return sinh(value.m_value);
+    return sinh(value);
 }
 
-Double Math::_s_Sqrt(Double value)
+double Math::_s_Sqrt(double value)
 {
-    return sqrt(value.m_value);
+    return sqrt(value);
 }
 
-Double Math::_s_Tan(Double value)
+double Math::_s_Tan(double value)
 {
-    return tan(value.m_value);
+    return tan(value);
 }
 
-Double Math::_s_Tanh(Double value)
+double Math::_s_Tanh(double value)
 {
-    return tanh(value.m_value);
+    return tanh(value);
 }
 
-Double Math::_s_FMod(Double x, Double y)
+double Math::_s_FMod(double x, double y)
 {
-    return fmod(x.m_value, y.m_value);
+    return fmod(x, y);
 }
 
-Double Math::_s_ModF(Double x, gc_ptr<Double> y)
+double Math::_s_ModF(double x, gc_ptr<double> y)
 {
-    return modf(x.m_value, &y->m_value);
+    return modf(x, y);
 }
 
 gc_obj_ref<MulticastDelegate> MulticastDelegate::_s_CreateDelegateLike(gc_obj_ref<MulticastDelegate> delegate, gc_obj_ref<SZArray_1<Delegate>> invocationList)
@@ -260,7 +260,7 @@ gc_obj_ref<MulticastDelegate> MulticastDelegate::_s_CreateDelegateLike(gc_obj_re
     }
 }
 
-void RuntimeImports::_s_RhZeroMemory(::natsu::gc_ptr<void> b, ::System_Private_CorLib::System::UInt64 byteLength)
+void RuntimeImports::_s_RhZeroMemory(::natsu::gc_ptr<void> b, uint64_t byteLength)
 {
-    std::memset(b.ptr_, 0, byteLength.m_value);
+    std::memset(b.ptr_, 0, byteLength);
 }

+ 6 - 6
src/Native/natsu.gc.cpp

@@ -388,7 +388,7 @@ static void prvInsertBlockIntoFreeList(BlockLink_t *pBlockToInsert)
     }
 }
 
-using namespace System_Private_CorLib::System;
+using namespace System_Private_CoreLib::System;
 using namespace Chino_Kernel::Chino::Memory;
 using namespace natsu;
 
@@ -402,16 +402,16 @@ gc_obj_ref<Object> natsu::gc_alloc(const vtable_t &vtable, size_t size)
     return ptr;
 }
 
-Int32 MemoryManager::_s_GetUsedMemorySize()
+int32_t MemoryManager::_s_GetUsedMemorySize()
 {
 #if _WIN32
-    return (int32_t)(6 * 1024 * 1024 - freeBytesRemaining_);
+    return 6 * 1024 * 1024 - freeBytesRemaining_;
 #else
-    return (int32_t)(size_t(&_heap_end[0] - &_heap_start[0]) - freeBytesRemaining_);
+    return size_t(&_heap_end[0] - &_heap_start[0]) - freeBytesRemaining_;
 #endif
 }
 
-Int32 MemoryManager::_s_GetFreeMemorySize()
+int32_t MemoryManager::_s_GetFreeMemorySize()
 {
-    return (int32_t)freeBytesRemaining_;
+    return freeBytesRemaining_;
 }

+ 18 - 11
src/Native/natsu.runtime.cpp

@@ -1,25 +1,25 @@
-#include "System.Private.CorLib.h"
+#include "System.Private.CoreLib.h"
 #include <algorithm>
 #include <stdexcept>
 
 using namespace natsu;
 using namespace natsu::stack;
 using namespace natsu::ops;
-using namespace System_Private_CorLib;
-using namespace System_Private_CorLib::System;
-using namespace System_Private_CorLib::System::Runtime::CompilerServices;
+using namespace System_Private_CoreLib;
+using namespace System_Private_CoreLib::System;
+using namespace System_Private_CoreLib::System::Runtime::CompilerServices;
 
 void InitializeHeap() noexcept;
 
-gc_obj_ref<::System_Private_CorLib::System::String> natsu::load_string(std::u16string_view string)
+gc_obj_ref<String> natsu::load_string(std::u16string_view string)
 {
-    auto dest = System_Private_CorLib::System::String::_s_FastAllocateString(string.length());
+    auto dest = String::_s_FastAllocateString(string.length());
     std::copy(string.begin(), string.end(), &dest->_firstChar);
     (&dest->_firstChar)[string.length()] = 0;
     return dest;
 }
 
-std::u16string_view natsu::to_string_view(gc_obj_ref<::System_Private_CorLib::System::String> string)
+std::u16string_view natsu::to_string_view(gc_obj_ref<String> string)
 {
     if (!string)
         return {};
@@ -28,22 +28,22 @@ std::u16string_view natsu::to_string_view(gc_obj_ref<::System_Private_CorLib::Sy
 
 void natsu::throw_null_ref_exception()
 {
-    throw make_exception(make_object<System_Private_CorLib::System::NullReferenceException>());
+    throw make_exception(make_object<NullReferenceException>());
 }
 
 void natsu::throw_invalid_cast_exception()
 {
-    throw make_exception(make_object<System_Private_CorLib::System::InvalidCastException>());
+    throw make_exception(make_object<InvalidCastException>());
 }
 
 void natsu::throw_index_out_of_range_exception()
 {
-    throw make_exception(make_object<System_Private_CorLib::System::IndexOutOfRangeException>());
+    throw make_exception(make_object<IndexOutOfRangeException>());
 }
 
 void natsu::throw_overflow_exception()
 {
-    throw make_exception(make_object<System_Private_CorLib::System::OverflowException>());
+    throw make_exception(make_object<OverflowException>());
 }
 
 void natsu::pure_call()
@@ -62,3 +62,10 @@ void ops::throw_(const stack::O &obj)
     check_null_obj_ref(obj);
     throw make_exception(stack_to<gc_obj_ref<Exception>>(obj));
 }
+
+#ifndef _MSC_VER
+namespace __cxxabiv1
+{
+std::terminate_handler __terminate_handler = abort;
+}
+#endif

+ 141 - 176
src/Native/natsu.runtime.h

@@ -23,7 +23,7 @@ namespace stack
         constexpr int32(int32_t value)
             : value_(value) {}
 
-        constexpr bool istrue() const noexcept
+        constexpr operator bool() const noexcept
         {
             return value_;
         }
@@ -37,7 +37,7 @@ namespace stack
         constexpr int64(int64_t value)
             : value_(value) {}
 
-        constexpr bool istrue() const noexcept
+        constexpr operator bool() const noexcept
         {
             return value_;
         }
@@ -51,7 +51,7 @@ namespace stack
         constexpr native_int(intptr_t value)
             : value_(value) {}
 
-        constexpr bool istrue() const noexcept
+        constexpr operator bool() const noexcept
         {
             return value_;
         }
@@ -74,7 +74,7 @@ namespace stack
         constexpr Ref(uintptr_t value)
             : value_(value) {}
 
-        constexpr bool istrue() const noexcept
+        constexpr operator bool() const noexcept
         {
             return value_;
         }
@@ -88,7 +88,7 @@ namespace stack
         constexpr O(uintptr_t value)
             : value_(value) {}
 
-        constexpr bool istrue() const noexcept
+        constexpr operator bool() const noexcept
         {
             return value_;
         }
@@ -102,12 +102,12 @@ namespace stack
     static constexpr O null = 0;
 }
 
-gc_obj_ref<::System_Private_CorLib::System::Object> gc_alloc(const vtable_t &vtable, size_t size);
+gc_obj_ref<::System_Private_CoreLib::System::Object> gc_alloc(const vtable_t &vtable, size_t size);
 
 template <class T>
 gc_obj_ref<T> gc_new(size_t size)
 {
-    auto obj = gc_alloc(vtable_holder<typename T::VTable>::get(), size);
+    auto obj = gc_alloc(vtable_holder<typename to_clr_type_t<T>::VTable>::get(), size);
     return obj.template cast<T>();
 }
 
@@ -118,17 +118,17 @@ gc_obj_ref<T> gc_new()
 }
 
 template <class T>
-gc_obj_ref<::System_Private_CorLib::System::SZArray_1<T>> gc_new_array(stack::int32 length)
+gc_obj_ref<::System_Private_CoreLib::System::SZArray_1<T>> gc_new_array(stack::int32 length)
 {
-    using obj_t = ::System_Private_CorLib::System::SZArray_1<T>;
+    using obj_t = ::System_Private_CoreLib::System::SZArray_1<T>;
     auto size = sizeof(obj_t) + (size_t)length.value_ * sizeof(T);
     auto obj = gc_new<obj_t>(size);
     obj->Length = length.value_;
     return obj;
 }
 
-gc_obj_ref<::System_Private_CorLib::System::String> load_string(std::u16string_view string);
-std::u16string_view to_string_view(gc_obj_ref<::System_Private_CorLib::System::String> string);
+gc_obj_ref<::System_Private_CoreLib::System::String> load_string(std::u16string_view string);
+std::u16string_view to_string_view(gc_obj_ref<::System_Private_CoreLib::System::String> string);
 
 template <class T, class... TArgs>
 auto make_object(TArgs... args)
@@ -183,28 +183,28 @@ void check_condition(TCond &&condition, TArgs &&... args)
 
 inline void check_null_obj_ref(stack::O obj)
 {
-    if (!obj.istrue())
+    if (!obj)
         throw_null_ref_exception();
 }
 
 inline void check_null_obj_ref(stack::native_int addr)
 {
-    if (!addr.istrue())
+    if (!addr)
         throw_null_ref_exception();
 }
 
 inline void check_null_obj_ref(stack::Ref addr)
 {
-    if (!addr.istrue())
+    if (!addr)
         throw_null_ref_exception();
 }
 
 template <class T>
 struct runtime_type_holder
 {
-    static gc_obj_ref<::System_Private_CorLib::System::RuntimeType> get()
+    static gc_obj_ref<::System_Private_CoreLib::System::RuntimeType> get()
     {
-        using namespace ::System_Private_CorLib::System;
+        using namespace ::System_Private_CoreLib::System;
         static auto type = make_object<RuntimeType>(
             reinterpret_cast<intptr_t>(&vtable_holder<typename T::VTable>::get()));
         return type;
@@ -255,45 +255,45 @@ namespace stack
         };
 
         template <>
-        struct stack_from_impl<::System_Private_CorLib::System::IntPtr>
+        struct stack_from_impl<::System_Private_CoreLib::System::IntPtr>
         {
-            native_int operator()(const ::System_Private_CorLib::System::IntPtr &value) const noexcept
+            native_int operator()(const ::System_Private_CoreLib::System::IntPtr &value) const noexcept
             {
                 return (intptr_t) static_cast<uintptr_t>(value._value);
             }
         };
 
         template <>
-        struct stack_from_impl<::System_Private_CorLib::System::UIntPtr>
+        struct stack_from_impl<::System_Private_CoreLib::System::UIntPtr>
         {
-            native_int operator()(const ::System_Private_CorLib::System::UIntPtr &value) const noexcept
+            native_int operator()(const ::System_Private_CoreLib::System::UIntPtr &value) const noexcept
             {
                 return (intptr_t) static_cast<uintptr_t>(value._value);
             }
         };
 
-#define DEFINE_STACK_FROM_CAST(From, To, Med, Cast)                    \
-    template <>                                                        \
-    struct stack_from_impl<From>                                       \
-    {                                                                  \
-        To operator()(const From &value) const noexcept                \
-        {                                                              \
-            return static_cast<Cast>(static_cast<Med>(value.m_value)); \
-        }                                                              \
+#define DEFINE_STACK_FROM_CAST(From, To, Med, Cast)            \
+    template <>                                                \
+    struct stack_from_impl<From>                               \
+    {                                                          \
+        To operator()(const From &value) const noexcept        \
+        {                                                      \
+            return static_cast<Cast>(static_cast<Med>(value)); \
+        }                                                      \
     };
 
-        DEFINE_STACK_FROM_CAST(::System_Private_CorLib::System::Boolean, int32, uint32_t, int32_t);
-        DEFINE_STACK_FROM_CAST(::System_Private_CorLib::System::SByte, int32, int32_t, int32_t);
-        DEFINE_STACK_FROM_CAST(::System_Private_CorLib::System::Byte, int32, uint32_t, int32_t);
-        DEFINE_STACK_FROM_CAST(::System_Private_CorLib::System::Char, int32, uint32_t, int32_t);
-        DEFINE_STACK_FROM_CAST(::System_Private_CorLib::System::Int16, int32, int32_t, int32_t);
-        DEFINE_STACK_FROM_CAST(::System_Private_CorLib::System::UInt16, int32, uint32_t, int32_t);
-        DEFINE_STACK_FROM_CAST(::System_Private_CorLib::System::Int32, int32, int32_t, int32_t);
-        DEFINE_STACK_FROM_CAST(::System_Private_CorLib::System::UInt32, int32, uint32_t, int32_t);
-        DEFINE_STACK_FROM_CAST(::System_Private_CorLib::System::Int64, int64, int64_t, int64_t);
-        DEFINE_STACK_FROM_CAST(::System_Private_CorLib::System::UInt64, int64, uint64_t, int64_t);
-        DEFINE_STACK_FROM_CAST(::System_Private_CorLib::System::Single, F, float, double);
-        DEFINE_STACK_FROM_CAST(::System_Private_CorLib::System::Double, F, double, double);
+        DEFINE_STACK_FROM_CAST(bool, int32, uint32_t, int32_t);
+        DEFINE_STACK_FROM_CAST(int8_t, int32, int32_t, int32_t);
+        DEFINE_STACK_FROM_CAST(uint8_t, int32, uint32_t, int32_t);
+        DEFINE_STACK_FROM_CAST(char16_t, int32, uint32_t, int32_t);
+        DEFINE_STACK_FROM_CAST(int16_t, int32, int32_t, int32_t);
+        DEFINE_STACK_FROM_CAST(uint16_t, int32, uint32_t, int32_t);
+        DEFINE_STACK_FROM_CAST(int32_t, int32, int32_t, int32_t);
+        DEFINE_STACK_FROM_CAST(uint32_t, int32, uint32_t, int32_t);
+        DEFINE_STACK_FROM_CAST(int64_t, int64, int64_t, int64_t);
+        DEFINE_STACK_FROM_CAST(uint64_t, int64, uint64_t, int64_t);
+        DEFINE_STACK_FROM_CAST(float, F, float, double);
+        DEFINE_STACK_FROM_CAST(double, F, double, double);
 
 #undef DEFINE_STACK_FROM_CAST
 
@@ -315,7 +315,7 @@ namespace stack
             TTo operator()(TFrom value)
             {
                 if constexpr (natsu::is_enum_v<TTo>)
-                    return static_cast<TTo>(value.value_);
+                    return TTo { static_cast<decltype(TTo::value__)>(value.value_) };
                 else
                     return value;
             }
@@ -384,33 +384,33 @@ namespace stack
             return static_cast<Med>(value.value_);      \
         }                                               \
     };
-        DEFINE_STACK_TO_CAST(int32, ::System_Private_CorLib::System::Boolean, bool);
-        DEFINE_STACK_TO_CAST(int32, ::System_Private_CorLib::System::SByte, int8_t);
-        DEFINE_STACK_TO_CAST(int32, ::System_Private_CorLib::System::Byte, uint8_t);
-        DEFINE_STACK_TO_CAST(int32, ::System_Private_CorLib::System::Char, char16_t);
-        DEFINE_STACK_TO_CAST(int32, ::System_Private_CorLib::System::Int16, int16_t);
-        DEFINE_STACK_TO_CAST(int32, ::System_Private_CorLib::System::UInt16, uint16_t);
-        DEFINE_STACK_TO_CAST(int32, ::System_Private_CorLib::System::Int32, int32_t);
-        DEFINE_STACK_TO_CAST(int32, ::System_Private_CorLib::System::UInt32, uint32_t);
-        DEFINE_STACK_TO_CAST(int32, ::System_Private_CorLib::System::IntPtr, intptr_t);
-        DEFINE_STACK_TO_CAST(int32, ::System_Private_CorLib::System::UIntPtr, uintptr_t);
-
-        DEFINE_STACK_TO_CAST(native_int, ::System_Private_CorLib::System::Boolean, bool);
-        DEFINE_STACK_TO_CAST(native_int, ::System_Private_CorLib::System::SByte, int8_t);
-        DEFINE_STACK_TO_CAST(native_int, ::System_Private_CorLib::System::Byte, uint8_t);
-        DEFINE_STACK_TO_CAST(native_int, ::System_Private_CorLib::System::Char, char16_t);
-        DEFINE_STACK_TO_CAST(native_int, ::System_Private_CorLib::System::Int16, int16_t);
-        DEFINE_STACK_TO_CAST(native_int, ::System_Private_CorLib::System::UInt16, uint16_t);
-        DEFINE_STACK_TO_CAST(native_int, ::System_Private_CorLib::System::Int32, int32_t);
-        DEFINE_STACK_TO_CAST(native_int, ::System_Private_CorLib::System::UInt32, uint32_t);
-        DEFINE_STACK_TO_CAST(native_int, ::System_Private_CorLib::System::IntPtr, intptr_t);
-        DEFINE_STACK_TO_CAST(native_int, ::System_Private_CorLib::System::UIntPtr, uintptr_t);
-
-        DEFINE_STACK_TO_CAST(int64, ::System_Private_CorLib::System::Int64, int64_t);
-        DEFINE_STACK_TO_CAST(int64, ::System_Private_CorLib::System::UInt64, uint64_t);
-
-        DEFINE_STACK_TO_CAST(F, ::System_Private_CorLib::System::Single, float);
-        DEFINE_STACK_TO_CAST(F, ::System_Private_CorLib::System::Double, double);
+        DEFINE_STACK_TO_CAST(int32, bool, bool);
+        DEFINE_STACK_TO_CAST(int32, int8_t, int8_t);
+        DEFINE_STACK_TO_CAST(int32, uint8_t, uint8_t);
+        DEFINE_STACK_TO_CAST(int32, char16_t, char16_t);
+        DEFINE_STACK_TO_CAST(int32, int16_t, int16_t);
+        DEFINE_STACK_TO_CAST(int32, uint16_t, uint16_t);
+        DEFINE_STACK_TO_CAST(int32, int32_t, int32_t);
+        DEFINE_STACK_TO_CAST(int32, uint32_t, uint32_t);
+        DEFINE_STACK_TO_CAST(int32, ::System_Private_CoreLib::System::IntPtr, intptr_t);
+        DEFINE_STACK_TO_CAST(int32, ::System_Private_CoreLib::System::UIntPtr, uintptr_t);
+
+        DEFINE_STACK_TO_CAST(native_int, bool, bool);
+        DEFINE_STACK_TO_CAST(native_int, int8_t, int8_t);
+        DEFINE_STACK_TO_CAST(native_int, uint8_t, uint8_t);
+        DEFINE_STACK_TO_CAST(native_int, char16_t, char16_t);
+        DEFINE_STACK_TO_CAST(native_int, int16_t, int16_t);
+        DEFINE_STACK_TO_CAST(native_int, uint16_t, uint16_t);
+        DEFINE_STACK_TO_CAST(native_int, int32_t, int32_t);
+        DEFINE_STACK_TO_CAST(native_int, uint32_t, uint32_t);
+        DEFINE_STACK_TO_CAST(native_int, ::System_Private_CoreLib::System::IntPtr, intptr_t);
+        DEFINE_STACK_TO_CAST(native_int, ::System_Private_CoreLib::System::UIntPtr, uintptr_t);
+
+        DEFINE_STACK_TO_CAST(int64, int64_t, int64_t);
+        DEFINE_STACK_TO_CAST(int64, uint64_t, uint64_t);
+
+        DEFINE_STACK_TO_CAST(F, float, float);
+        DEFINE_STACK_TO_CAST(F, double, double);
 
 #undef DEFINE_STACK_TO_CAST
 
@@ -435,9 +435,9 @@ namespace stack
         };
 
         template <class T>
-        struct box_impl<::System_Private_CorLib::System::Nullable_1<T>>
+        struct box_impl<::System_Private_CoreLib::System::Nullable_1<T>>
         {
-            O operator()(const ::System_Private_CorLib::System::Nullable_1<T> &value) const noexcept
+            O operator()(const ::System_Private_CoreLib::System::Nullable_1<T> &value) const noexcept
             {
                 if (value.hasValue)
                 {
@@ -457,7 +457,7 @@ namespace stack
         {
             Ref operator()(const O &obj)
             {
-                using ::System_Private_CorLib::System::Object;
+                using ::System_Private_CoreLib::System::Object;
 
                 // check_null_obj_ref(obj);
                 auto box = stack_to<gc_obj_ref<Object>>(obj).template as<T>();
@@ -469,14 +469,14 @@ namespace stack
         };
 
         template <class T>
-        struct unbox_impl<::System_Private_CorLib::System::Nullable_1<T>>
+        struct unbox_impl<::System_Private_CoreLib::System::Nullable_1<T>>
         {
             Ref operator()(const O &obj)
             {
-                using ::System_Private_CorLib::System::Nullable_1;
-                using ::System_Private_CorLib::System::Object;
+                using ::System_Private_CoreLib::System::Nullable_1;
+                using ::System_Private_CoreLib::System::Object;
 
-                if (obj.istrue())
+                if (obj)
                 {
                     auto box = stack_to<gc_obj_ref<Object>>(obj).template as<T>();
                     if (box)
@@ -503,7 +503,7 @@ namespace stack
         {
             auto operator()(const O &obj)
             {
-                using ::System_Private_CorLib::System::Object;
+                using ::System_Private_CoreLib::System::Object;
 
                 // check_null_obj_ref(obj);
                 auto box = stack_to<gc_obj_ref<Object>>(obj).template as<T>();
@@ -526,14 +526,14 @@ namespace stack
         };
 
         template <class T>
-        struct unbox_any_impl<::System_Private_CorLib::System::Nullable_1<T>>
+        struct unbox_any_impl<::System_Private_CoreLib::System::Nullable_1<T>>
         {
-            ::System_Private_CorLib::System::Nullable_1<T> operator()(const O &obj)
+            ::System_Private_CoreLib::System::Nullable_1<T> operator()(const O &obj)
             {
-                using ::System_Private_CorLib::System::Nullable_1;
-                using ::System_Private_CorLib::System::Object;
+                using ::System_Private_CoreLib::System::Nullable_1;
+                using ::System_Private_CoreLib::System::Object;
 
-                if (obj.istrue())
+                if (obj)
                 {
                     auto box = stack_to<gc_obj_ref<Object>>(obj).template as<T>();
                     if (box)
@@ -557,14 +557,14 @@ namespace stack
         {
             O operator()(const O &obj) const noexcept
             {
-                if (obj.istrue() && obj.header().vtable_as<typename T::VTable>())
+                if (obj && obj.header().vtable_as<typename natsu::to_clr_type_t<T>::VTable>())
                     return obj;
                 return null;
             }
         };
 
         template <class T>
-        struct isinst_impl<::System_Private_CorLib::System::Nullable_1<T>>
+        struct isinst_impl<::System_Private_CoreLib::System::Nullable_1<T>>
         {
             O operator()(const O &obj) const noexcept
             {
@@ -585,11 +585,11 @@ namespace stack
         };
 
         template <class T>
-        struct castclass_impl<::System_Private_CorLib::System::Nullable_1<T>>
+        struct castclass_impl<::System_Private_CoreLib::System::Nullable_1<T>>
         {
             O operator()(const O &obj) const noexcept
             {
-                if (obj.istrue())
+                if (obj)
                 {
                     if (obj.header().vtable_as<typename T::VTable>())
                         return obj;
@@ -882,9 +882,9 @@ namespace ops
             value._ctor(value, std::forward<TArgs>(args)...);
             return stack_from(value);
         }
-        else if constexpr (std::is_same_v<T, ::System_Private_CorLib::System::String>)
+        else if constexpr (std::is_same_v<T, ::System_Private_CoreLib::System::String>)
         {
-            auto value = ::System_Private_CorLib::System::String::_s_Ctor(std::forward<TArgs>(args)...);
+            auto value = ::System_Private_CoreLib::System::String::_s_Ctor(std::forward<TArgs>(args)...);
             return stack_from(value);
         }
         else
@@ -952,55 +952,55 @@ namespace ops
 #define LDELEM_IMPL(name, type, value_type)                                                         \
     inline value_type ldelem_##name(const stack::O &obj, stack::int32 index)                        \
     {                                                                                               \
-        using ::System_Private_CorLib::System::SZArray_1;                                           \
+        using ::System_Private_CoreLib::System::SZArray_1;                                           \
         return stack_from(stack_to<gc_obj_ref<SZArray_1<type>>>(obj)->at((uint32_t)index.value_));  \
     }                                                                                               \
     inline value_type ldelem_##name(const stack::O &obj, stack::native_int index)                   \
     {                                                                                               \
-        using ::System_Private_CorLib::System::SZArray_1;                                           \
+        using ::System_Private_CoreLib::System::SZArray_1;                                           \
         return stack_from(stack_to<gc_obj_ref<SZArray_1<type>>>(obj)->at((uintptr_t)index.value_)); \
     }
 
-    LDELEM_IMPL(i1, ::System_Private_CorLib::System::SByte, stack::int32);
-    LDELEM_IMPL(i2, ::System_Private_CorLib::System::Int16, stack::int32);
-    LDELEM_IMPL(i4, ::System_Private_CorLib::System::Int32, stack::int32);
-    LDELEM_IMPL(i8, ::System_Private_CorLib::System::Int64, stack::int64);
-    LDELEM_IMPL(r4, ::System_Private_CorLib::System::Single, stack::F);
-    LDELEM_IMPL(r8, ::System_Private_CorLib::System::Double, stack::F);
-    LDELEM_IMPL(i, ::System_Private_CorLib::System::IntPtr, stack::native_int);
-    LDELEM_IMPL(u1, ::System_Private_CorLib::System::Byte, stack::int32);
-    LDELEM_IMPL(u2, ::System_Private_CorLib::System::UInt16, stack::int32);
-    LDELEM_IMPL(u4, ::System_Private_CorLib::System::UInt32, stack::int32);
-    LDELEM_IMPL(u8, ::System_Private_CorLib::System::UInt64, stack::int64);
-    LDELEM_IMPL(u, ::System_Private_CorLib::System::UIntPtr, stack::native_int);
+    LDELEM_IMPL(i1, int8_t, stack::int32);
+    LDELEM_IMPL(i2, int16_t, stack::int32);
+    LDELEM_IMPL(i4, int32_t, stack::int32);
+    LDELEM_IMPL(i8, int64_t, stack::int64);
+    LDELEM_IMPL(r4, float, stack::F);
+    LDELEM_IMPL(r8, double, stack::F);
+    LDELEM_IMPL(i, ::System_Private_CoreLib::System::IntPtr, stack::native_int);
+    LDELEM_IMPL(u1, uint8_t, stack::int32);
+    LDELEM_IMPL(u2, uint16_t, stack::int32);
+    LDELEM_IMPL(u4, uint32_t, stack::int32);
+    LDELEM_IMPL(u8, uint64_t, stack::int64);
+    LDELEM_IMPL(u, ::System_Private_CoreLib::System::UIntPtr, stack::native_int);
 
     inline stack::O ldelem_ref(const stack::O &obj, stack::int32 index)
     {
-        using ::System_Private_CorLib::System::Object;
-        using ::System_Private_CorLib::System::SZArray_1;
+        using ::System_Private_CoreLib::System::Object;
+        using ::System_Private_CoreLib::System::SZArray_1;
         return stack_from(stack_to<gc_obj_ref<SZArray_1<Object>>>(obj)->at((uint32_t)index.value_));
     }
 
     inline stack::O ldelem_ref(const stack::O &obj, stack::native_int index)
     {
-        using ::System_Private_CorLib::System::Object;
-        using ::System_Private_CorLib::System::SZArray_1;
+        using ::System_Private_CoreLib::System::Object;
+        using ::System_Private_CoreLib::System::SZArray_1;
         return stack_from(stack_to<gc_obj_ref<SZArray_1<Object>>>(obj)->at((uintptr_t)index.value_));
     }
 
     template <class T>
     inline auto ldelem(const stack::O &obj, stack::int32 index)
     {
-        using ::System_Private_CorLib::System::Object;
-        using ::System_Private_CorLib::System::SZArray_1;
+        using ::System_Private_CoreLib::System::Object;
+        using ::System_Private_CoreLib::System::SZArray_1;
         return stack_from(stack_to<gc_obj_ref<SZArray_1<T>>>(obj)->at((uint32_t)index.value_));
     }
 
     template <class T>
     inline auto ldelem(const stack::O &obj, stack::native_int index)
     {
-        using ::System_Private_CorLib::System::Object;
-        using ::System_Private_CorLib::System::SZArray_1;
+        using ::System_Private_CoreLib::System::Object;
+        using ::System_Private_CoreLib::System::SZArray_1;
         return stack_from(stack_to<gc_obj_ref<SZArray_1<T>>>(obj)->at((uintptr_t)index.value_));
     }
 
@@ -1009,38 +1009,38 @@ namespace ops
 #define STELEM_IMPL(name, type, value_type, cast)                                                       \
     inline void stelem_##name(const stack::O &obj, stack::int32 index, value_type value)                \
     {                                                                                                   \
-        using ::System_Private_CorLib::System::SZArray_1;                                               \
+        using ::System_Private_CoreLib::System::SZArray_1;                                               \
         stack_to<gc_obj_ref<SZArray_1<type>>>(obj)->at(index.value_) = static_cast<cast>(value.value_); \
     }
 
-    STELEM_IMPL(i1, ::System_Private_CorLib::System::SByte, stack::int32, int8_t);
-    STELEM_IMPL(i2, ::System_Private_CorLib::System::Int16, stack::int32, int16_t);
-    STELEM_IMPL(i4, ::System_Private_CorLib::System::Int32, stack::int32, int32_t);
-    STELEM_IMPL(i8, ::System_Private_CorLib::System::Int64, stack::int64, int64_t);
-    STELEM_IMPL(r4, ::System_Private_CorLib::System::Single, stack::F, float);
-    STELEM_IMPL(r8, ::System_Private_CorLib::System::Double, stack::F, double);
-    STELEM_IMPL(i, ::System_Private_CorLib::System::IntPtr, stack::native_int, intptr_t);
+    STELEM_IMPL(i1, int8_t, stack::int32, int8_t);
+    STELEM_IMPL(i2, int16_t, stack::int32, int16_t);
+    STELEM_IMPL(i4, int32_t, stack::int32, int32_t);
+    STELEM_IMPL(i8, int64_t, stack::int64, int64_t);
+    STELEM_IMPL(r4, float, stack::F, float);
+    STELEM_IMPL(r8, double, stack::F, double);
+    STELEM_IMPL(i, ::System_Private_CoreLib::System::IntPtr, stack::native_int, intptr_t);
 
     inline void stelem_ref(const stack::O &obj, stack::int32 index, stack::O value)
     {
-        using ::System_Private_CorLib::System::Object;
-        using ::System_Private_CorLib::System::SZArray_1;
+        using ::System_Private_CoreLib::System::Object;
+        using ::System_Private_CoreLib::System::SZArray_1;
         stack_to<gc_obj_ref<SZArray_1<Object>>>(obj)->at(index.value_) = stack_to<gc_obj_ref<Object>>(value);
     }
 
     template <class T, class TStack>
     void stelem(const stack::O &obj, stack::int32 index, TStack value)
     {
-        using ::System_Private_CorLib::System::Object;
-        using ::System_Private_CorLib::System::SZArray_1;
+        using ::System_Private_CoreLib::System::Object;
+        using ::System_Private_CoreLib::System::SZArray_1;
         stack_to<gc_obj_ref<SZArray_1<T>>>(obj)->at((uint32_t)index.value_) = stack_to<variable_type_t<T>>(value);
     }
 
     template <class T, class TStack>
     void stelem(const stack::O &obj, stack::native_int index, TStack value)
     {
-        using ::System_Private_CorLib::System::Object;
-        using ::System_Private_CorLib::System::SZArray_1;
+        using ::System_Private_CoreLib::System::Object;
+        using ::System_Private_CoreLib::System::SZArray_1;
         stack_to<gc_obj_ref<SZArray_1<T>>>(obj)->at((uint32_t)index.value_) = stack_to<variable_type_t<T>>(value);
     }
 
@@ -1297,7 +1297,7 @@ namespace ops
     template <class T>
     stack::Ref ldelema(const stack::O &obj, stack::int32 index)
     {
-        using ::System_Private_CorLib::System::SZArray_1;
+        using ::System_Private_CoreLib::System::SZArray_1;
         return stack_from(stack_to<gc_obj_ref<SZArray_1<T>>>(obj)->ref_at(index.value_));
     }
 
@@ -1314,9 +1314,9 @@ namespace ops
     }
 
     template <class T>
-    ::System_Private_CorLib::System::RuntimeTypeHandle ldtoken_type()
+    ::System_Private_CoreLib::System::RuntimeTypeHandle ldtoken_type()
     {
-        return { runtime_type_holder<T>::get() };
+        return { runtime_type_holder<natsu::to_clr_type_t<T>>::get() };
     }
 
     [[noreturn]] void throw_(const stack::O &obj);
@@ -1345,49 +1345,14 @@ namespace ops
 }
 
 template <class T>
-gc_ref<T> unbox_exact(gc_obj_ref<::System_Private_CorLib::System::Object> value)
+gc_ref<T> unbox_exact(gc_obj_ref<::System_Private_CoreLib::System::Object> value)
 {
     auto box = value.cast<T>();
     return gc_ref_from_ref(*box);
 }
-
-template <size_t N>
-struct string_literal : public System_Private_CorLib::System::Object
-{
-    ::System_Private_CorLib::System::Int32 _stringLength;
-    std::array<::System_Private_CorLib::System::Char, N + 1> _firstChar;
-
-    constexpr string_literal(std::u16string_view str)
-        : _stringLength((int32_t)N), _firstChar(init_array(str, std::make_index_sequence<N>()))
-    {
-    }
-
-    template <size_t... I>
-    constexpr std::array<::System_Private_CorLib::System::Char, N + 1> init_array(std::u16string_view str, std::index_sequence<I...>)
-    {
-        return { str[I]..., 0 };
-    }
-};
-
-template <class TObject, class TValue>
-struct static_object
-{
-    object_header header_;
-    TValue value_;
-
-    constexpr static_object(TValue value)
-        : header_({ OBJ_ATTR_NONE, &vtable_holder<typename TObject::VTable>::get() }), value_(value)
-    {
-    }
-
-    constexpr gc_obj_ref<TObject> get() const noexcept
-    {
-        return gc_obj_ref<TObject>(reinterpret_cast<TObject *>(const_cast<TValue *>(&value_)));
-    }
-};
 }
 
-namespace System_Private_CorLib
+namespace System_Private_CoreLib
 {
 template <class T>
 void System::ByReference_1<T>::_ctor(::natsu::gc_ref<System::ByReference_1<T>> _this, ::natsu::gc_ref<::natsu::variable_type_t<T>> value)
@@ -1408,13 +1373,13 @@ template <class T>
 }
 
 template <class T>
-::System_Private_CorLib::System::Int32 Internal::Runtime::CompilerServices::Unsafe::_s_SizeOf()
+int32_t Internal::Runtime::CompilerServices::Unsafe::_s_SizeOf()
 {
     return sizeof(T);
 }
 
 template <class T>
-::natsu::variable_type_t<T> Internal::Runtime::CompilerServices::Unsafe::_s_As(::natsu::gc_obj_ref<::System_Private_CorLib::System::Object> value)
+::natsu::variable_type_t<T> Internal::Runtime::CompilerServices::Unsafe::_s_As(::natsu::gc_obj_ref<::System_Private_CoreLib::System::Object> value)
 {
     return ::natsu::gc_obj_ref<T>(reinterpret_cast<T *>(value.ptr_));
 }
@@ -1426,19 +1391,19 @@ template <class TFrom, class TTo>
 }
 
 template <class T>
-::System_Private_CorLib::System::Boolean Internal::Runtime::CompilerServices::Unsafe::_s_AreSame(::natsu::gc_ref<::natsu::variable_type_t<T>> left, ::natsu::gc_ref<::natsu::variable_type_t<T>> right)
+bool Internal::Runtime::CompilerServices::Unsafe::_s_AreSame(::natsu::gc_ref<::natsu::variable_type_t<T>> left, ::natsu::gc_ref<::natsu::variable_type_t<T>> right)
 {
     return left.ptr_ == right.ptr_;
 }
 
 template <class T>
-::System_Private_CorLib::System::Boolean Internal::Runtime::CompilerServices::Unsafe::_s_IsAddressGreaterThan(::natsu::gc_ref<::natsu::variable_type_t<T>> left, ::natsu::gc_ref<::natsu::variable_type_t<T>> right)
+bool Internal::Runtime::CompilerServices::Unsafe::_s_IsAddressGreaterThan(::natsu::gc_ref<::natsu::variable_type_t<T>> left, ::natsu::gc_ref<::natsu::variable_type_t<T>> right)
 {
     return left.ptr_ > right.ptr_;
 }
 
 template <class T>
-::System_Private_CorLib::System::Boolean Internal::Runtime::CompilerServices::Unsafe::_s_IsAddressLessThan(::natsu::gc_ref<::natsu::variable_type_t<T>> left, ::natsu::gc_ref<::natsu::variable_type_t<T>> right)
+bool Internal::Runtime::CompilerServices::Unsafe::_s_IsAddressLessThan(::natsu::gc_ref<::natsu::variable_type_t<T>> left, ::natsu::gc_ref<::natsu::variable_type_t<T>> right)
 {
     return left.ptr_ < right.ptr_;
 }
@@ -1455,7 +1420,7 @@ template <class T>
 }
 
 template <class T>
-::natsu::variable_type_t<T> Internal::Runtime::CompilerServices::Unsafe::_s_ReadUnaligned(::natsu::gc_ref<::System_Private_CorLib::System::Byte> source)
+::natsu::variable_type_t<T> Internal::Runtime::CompilerServices::Unsafe::_s_ReadUnaligned(::natsu::gc_ref<uint8_t> source)
 {
     auto obj = natsu::make_object_uninit<T>();
     if constexpr (natsu::is_value_type_v<T>)
@@ -1475,7 +1440,7 @@ void Internal::Runtime::CompilerServices::Unsafe::_s_WriteUnaligned(::natsu::gc_
 }
 
 template <class T>
-void Internal::Runtime::CompilerServices::Unsafe::_s_WriteUnaligned(::natsu::gc_ref<::System_Private_CorLib::System::Byte> destination, ::natsu::variable_type_t<T> value)
+void Internal::Runtime::CompilerServices::Unsafe::_s_WriteUnaligned(::natsu::gc_ref<uint8_t> destination, ::natsu::variable_type_t<T> value)
 {
     if constexpr (natsu::is_value_type_v<T>)
         std::memcpy(destination.ptr_, &value, sizeof(T));
@@ -1484,9 +1449,9 @@ void Internal::Runtime::CompilerServices::Unsafe::_s_WriteUnaligned(::natsu::gc_
 }
 
 template <class T>
-::natsu::gc_ref<::natsu::variable_type_t<T>> Internal::Runtime::CompilerServices::Unsafe::_s_AddByteOffset(::natsu::gc_ref<::natsu::variable_type_t<T>> source, ::System_Private_CorLib::System::IntPtr byteOffset)
+::natsu::gc_ref<::natsu::variable_type_t<T>> Internal::Runtime::CompilerServices::Unsafe::_s_AddByteOffset(::natsu::gc_ref<::natsu::variable_type_t<T>> source, ::System_Private_CoreLib::System::IntPtr byteOffset)
 {
-    return ::natsu::gc_ref<::natsu::variable_type_t<T>>(reinterpret_cast<uintptr_t>(source.ptr_) + reinterpret_cast<intptr_t>(byteOffset._value.ptr_));
+    return ::natsu::gc_ref_from_addr<::natsu::variable_type_t<T>>(reinterpret_cast<uintptr_t>(source.ptr_) + reinterpret_cast<intptr_t>(byteOffset._value.ptr_));
 }
 
 template <class T>
@@ -1496,25 +1461,25 @@ template <class T>
 }
 
 template <class T>
-::System_Private_CorLib::System::IntPtr Internal::Runtime::CompilerServices::Unsafe::_s_ByteOffset(::natsu::gc_ref<::natsu::variable_type_t<T>> origin, ::natsu::gc_ref<::natsu::variable_type_t<T>> target)
+System::IntPtr Internal::Runtime::CompilerServices::Unsafe::_s_ByteOffset(::natsu::gc_ref<::natsu::variable_type_t<T>> origin, ::natsu::gc_ref<::natsu::variable_type_t<T>> target)
 {
     return reinterpret_cast<intptr_t>(target.ptr_) - reinterpret_cast<intptr_t>(origin.ptr_);
 }
 
 template <class T>
-::System_Private_CorLib::System::Boolean System::Runtime::CompilerServices::RuntimeHelpers::_s_IsReferenceOrContainsReferences()
+bool System::Runtime::CompilerServices::RuntimeHelpers::_s_IsReferenceOrContainsReferences()
 {
     return true;
 }
 
 template <class T>
-::System_Private_CorLib::System::Boolean System::Runtime::CompilerServices::RuntimeHelpers::_s_IsBitwiseEquatable()
+bool System::Runtime::CompilerServices::RuntimeHelpers::_s_IsBitwiseEquatable()
 {
     return false;
 }
 
 template <class T>
-::natsu::gc_obj_ref<::System_Private_CorLib::System::Collections::Generic::EqualityComparer_1<T>> System::Collections::Generic::ComparerHelpers::_s_CreateDefaultEqualityComparer()
+::natsu::gc_obj_ref<System::Collections::Generic::EqualityComparer_1<T>> System::Collections::Generic::ComparerHelpers::_s_CreateDefaultEqualityComparer()
 {
     return natsu::null;
 }

+ 10 - 10
src/Native/natsu.threading.cpp

@@ -1,4 +1,4 @@
-#include "System.Private.CorLib.h"
+#include "System.Private.CoreLib.h"
 
 #if _MSC_VER
 #include <intrin.h>
@@ -6,12 +6,12 @@
 #endif
 
 using namespace natsu;
-using namespace System_Private_CorLib;
-using namespace System_Private_CorLib::System;
-using namespace System_Private_CorLib::System::Threading;
-using namespace System_Private_CorLib::System::Runtime::CompilerServices;
+using namespace System_Private_CoreLib;
+using namespace System_Private_CoreLib::System;
+using namespace System_Private_CoreLib::System::Threading;
+using namespace System_Private_CoreLib::System::Runtime::CompilerServices;
 
-Int32 Interlocked::_s_Exchange(gc_ref<Int32> location1, Int32 value)
+int32_t Interlocked::_s_Exchange(gc_ref<int32_t> location1, int32_t value)
 {
 #if _MSC_VER
     return _InterlockedExchange(reinterpret_cast<volatile long *>(location1.ptr_), value);
@@ -20,7 +20,7 @@ Int32 Interlocked::_s_Exchange(gc_ref<Int32> location1, Int32 value)
 #endif
 }
 
-Int64 Interlocked::_s_Exchange(gc_ref<Int64> location1, Int64 value)
+int64_t Interlocked::_s_Exchange(gc_ref<int64_t> location1, int64_t value)
 {
 #if _MSC_VER
     return _InterlockedExchange64(reinterpret_cast<volatile int64_t *>(location1.ptr_), value);
@@ -29,7 +29,7 @@ Int64 Interlocked::_s_Exchange(gc_ref<Int64> location1, Int64 value)
 #endif
 }
 
-Int64 Interlocked::_s_CompareExchange(gc_ref<Int64> location1, Int64 value, Int64 comparand)
+int64_t Interlocked::_s_CompareExchange(gc_ref<int64_t> location1, int64_t value, int64_t comparand)
 {
 #if _MSC_VER
     return _InterlockedCompareExchange64(reinterpret_cast<volatile int64_t *>(location1.ptr_), value, comparand);
@@ -51,7 +51,7 @@ gc_obj_ref<Object> Interlocked::_s_CompareExchange(gc_ref<gc_obj_ref<Object>> lo
 #endif
 }
 
-Int32 Interlocked::_s_ExchangeAdd(gc_ref<Int32> location1, Int32 value)
+int32_t Interlocked::_s_ExchangeAdd(gc_ref<int32_t> location1, int32_t value)
 {
 #if _MSC_VER
     return _InterlockedExchangeAdd(reinterpret_cast<volatile long *>(location1.ptr_), value);
@@ -60,7 +60,7 @@ Int32 Interlocked::_s_ExchangeAdd(gc_ref<Int32> location1, Int32 value)
 #endif
 }
 
-Int64 Interlocked::_s_ExchangeAdd(gc_ref<Int64> location1, Int64 value)
+int64_t Interlocked::_s_ExchangeAdd(gc_ref<int64_t> location1, int64_t value)
 {
 #if _MSC_VER
     return _InterlockedExchangeAdd64(reinterpret_cast<volatile int64_t *>(location1.ptr_), value);

+ 106 - 17
src/Native/natsu.typedef.h

@@ -10,10 +10,24 @@
 
 using namespace std::string_view_literals;
 
-namespace System_Private_CorLib
+namespace System_Private_CoreLib
 {
 namespace System
 {
+    struct Boolean;
+    struct SByte;
+    struct Byte;
+    struct Char;
+    struct UInt16;
+    struct Int16;
+    struct UInt32;
+    struct Int32;
+    struct UInt64;
+    struct Int64;
+    struct Single;
+    struct Double;
+    struct UIntPtr;
+    struct IntPtr;
     struct Exception;
     struct String;
     struct Object;
@@ -143,10 +157,43 @@ struct object_header
 };
 
 template <class T>
-constexpr bool is_value_type_v = T::TypeInfo::IsValueType;
+struct to_clr_type
+{
+    using type = T;
+};
+
+#define DEFINE_TO_CLR_TYPE(src, dest)                       \
+    template <>                                             \
+    struct to_clr_type<src>                                 \
+    {                                                       \
+        using type = ::System_Private_CoreLib::System::dest; \
+    };
+
+DEFINE_TO_CLR_TYPE(bool, Boolean);
+DEFINE_TO_CLR_TYPE(int8_t, SByte);
+DEFINE_TO_CLR_TYPE(uint8_t, Byte);
+DEFINE_TO_CLR_TYPE(char16_t, Char);
+DEFINE_TO_CLR_TYPE(uint16_t, UInt16);
+DEFINE_TO_CLR_TYPE(int16_t, Int16);
+DEFINE_TO_CLR_TYPE(uint32_t, UInt32);
+DEFINE_TO_CLR_TYPE(int32_t, Int32);
+DEFINE_TO_CLR_TYPE(uint64_t, UInt64);
+DEFINE_TO_CLR_TYPE(int64_t, Int64);
+DEFINE_TO_CLR_TYPE(float, Single);
+DEFINE_TO_CLR_TYPE(double, Double);
+//DEFINE_TO_CLR_TYPE(uintptr_t, UIntPtr);
+//DEFINE_TO_CLR_TYPE(intptr_t, IntPtr);
+
+#undef DEFINE_TO_CLR_TYPE
 
 template <class T>
-constexpr bool is_enum_v = T::TypeInfo::IsEnum;
+using to_clr_type_t = typename to_clr_type<T>::type;
+
+template <class T>
+constexpr bool is_value_type_v = to_clr_type_t<T>::TypeInfo::IsValueType;
+
+template <class T>
+constexpr bool is_enum_v = to_clr_type_t<T>::TypeInfo::IsEnum;
 
 template <class T, bool IsValueType>
 struct variable_type;
@@ -200,11 +247,6 @@ struct gc_ref
     {
     }
 
-    explicit constexpr gc_ref(uintptr_t ptr) noexcept
-        : ptr_(reinterpret_cast<T *>(ptr))
-    {
-    }
-
     explicit constexpr operator bool() const noexcept
     {
         return true;
@@ -238,6 +280,12 @@ gc_ref<T> gc_ref_from_ref(T &ref)
     return gc_ref<T>(ref);
 }
 
+template <class T>
+gc_ref<T> gc_ref_from_addr(uintptr_t addr)
+{
+    return gc_ref<T>(*reinterpret_cast<T *>(addr));
+}
+
 template <class T>
 struct gc_ptr
 {
@@ -418,7 +466,7 @@ struct gc_obj_ref
     {
         if (ptr_)
         {
-            auto vtable = header().template vtable_as<typename U::VTable>();
+            auto vtable = header().template vtable_as<typename natsu::to_clr_type_t<U>::VTable>();
             if (vtable)
                 return gc_obj_ref<U>(reinterpret_cast<U *>(ptr_));
         }
@@ -446,7 +494,7 @@ struct natsu_exception
     {
     }
 
-    gc_obj_ref<::System_Private_CorLib::System::Exception> exception_;
+    gc_obj_ref<::System_Private_CoreLib::System::Exception> exception_;
 };
 
 template <class T, class U>
@@ -520,6 +568,41 @@ struct vtable_class : public TBase, public vtable_impl_t<TBase, TIFaces>...
         int ignore[] = { 0, (vtable_impl_t<TBase, TIFaces>::override_vfunc_impl(name, func), 0)... };
     }
 };
+
+template <size_t N>
+struct string_literal
+{
+    int32_t _stringLength;
+    std::array<char16_t, N + 1> _firstChar;
+
+    constexpr string_literal(std::u16string_view str)
+        : _stringLength((int32_t)N), _firstChar(init_array(str, std::make_index_sequence<N>()))
+    {
+    }
+
+    template <size_t... I>
+    constexpr std::array<char16_t, N + 1> init_array(std::u16string_view str, std::index_sequence<I...>)
+    {
+        return { str[I]..., 0 };
+    }
+};
+
+template <class TObject, class TValue>
+struct static_object
+{
+    object_header header_;
+    TValue value_;
+
+    constexpr static_object(TValue value)
+        : header_({ OBJ_ATTR_NONE, &vtable_holder<typename TObject::VTable>::get() }), value_(value)
+    {
+    }
+
+    constexpr gc_obj_ref<TObject> get() const noexcept
+    {
+        return gc_obj_ref<TObject>(reinterpret_cast<TObject *>(const_cast<TValue *>(&value_)));
+    }
+};
 }
 
 #define NATSU_PRIMITIVE_IMPL_BYTE                     \
@@ -589,14 +672,20 @@ struct vtable_class : public TBase, public vtable_impl_t<TBase, TIFaces>...
     UIntPtr(uintptr_t value) : _value((uintptr_t)value) {} \
     operator uintptr_t() const noexcept { return (uintptr_t)_value; }
 
-#define NATSU_ENUM_IMPL_BYTE(name)                    \
-    name() = default;                                 \
-    constexpr name(uint8_t value) : value__(value) {} \
+#define NATSU_ENUM_IMPL_BYTE(name) \
+    name &operator=(int32_t value) \
+    {                              \
+        value__ = value;           \
+        return *this;              \
+    }                              \
     constexpr operator uint8_t() const noexcept { return value__; }
 
-#define NATSU_ENUM_IMPL_INT32(name)                   \
-    name() = default;                                 \
-    constexpr name(int32_t value) : value__(value) {} \
+#define NATSU_ENUM_IMPL_INT32(name) \
+    name &operator=(int32_t value)  \
+    {                               \
+        value__ = value;            \
+        return *this;               \
+    }                               \
     constexpr operator int32_t() const noexcept { return value__; }
 
 #define NATSU_OBJECT_IMPL
@@ -630,6 +719,6 @@ struct vtable_class : public TBase, public vtable_impl_t<TBase, TIFaces>...
     }                                                                \
     constexpr uintptr_t length() const noexcept                      \
     {                                                                \
-        return Length.m_value;                                       \
+        return Length;                                               \
     }                                                                \
     ::natsu::variable_type_t<T> elements_[0];

+ 8 - 8
src/Native/natsu.unicode.cpp

@@ -1,10 +1,10 @@
-#include "System.Private.CorLib.h"
+#include "System.Private.CoreLib.h"
 
 using namespace natsu;
-using namespace System_Private_CorLib;
-using namespace System_Private_CorLib::System;
-using namespace System_Private_CorLib::System::Diagnostics;
-using namespace System_Private_CorLib::System::Globalization;
+using namespace System_Private_CoreLib;
+using namespace System_Private_CoreLib::System;
+using namespace System_Private_CoreLib::System::Diagnostics;
+using namespace System_Private_CoreLib::System::Globalization;
 
 // 12:4:4 index table of the Unicode cateogry data.
 static const uint16_t s_pCategoryLevel1Index[] = {
@@ -1234,7 +1234,7 @@ static const uint8_t s_pNumericValues[] = {
     0x00, 0x00, 0x00, 0x20, 0x5f, 0xa0, 0x02, 0x42, 0x00, 0x00, 0x00, 0xa2, 0x94, 0x1a, 0x6d, 0x42
 };
 
-Byte CharUnicodeInfo::_s_InternalGetCategoryValue(Int32 ch, Int32 offset)
+uint8_t CharUnicodeInfo::_s_InternalGetCategoryValue(int32_t ch, int32_t offset)
 {
     Debug::_s_Assert(ch >= 0 && ch <= 0x10ffff, load_string(u"ch is not in valid Unicode range."sv));
     // Get the level 2 item from the highest 12 bit (8 - 19) of ch.
@@ -1255,7 +1255,7 @@ Byte CharUnicodeInfo::_s_InternalGetCategoryValue(Int32 ch, Int32 offset)
     return (uc);
 }
 
-UInt16 CharUnicodeInfo::_s_InternalGetDigitValues(Int32 ch)
+uint16_t CharUnicodeInfo::_s_InternalGetDigitValues(int32_t ch)
 {
     Debug::_s_Assert(ch >= 0 && ch <= 0x10ffff, load_string(u"ch is not in valid Unicode range."sv));
     // Get the level 2 item from the highest 12 bit (8 - 19) of ch.
@@ -1268,7 +1268,7 @@ UInt16 CharUnicodeInfo::_s_InternalGetDigitValues(Int32 ch)
     return s_pDigitValues[pBytePtr[(ch & 0x000f)]];
 }
 
-Double CharUnicodeInfo::_s_InternalGetNumericValue(Int32 ch)
+double CharUnicodeInfo::_s_InternalGetNumericValue(int32_t ch)
 {
     Debug::_s_Assert(ch >= 0 && ch <= 0x10ffff, load_string(u"ch is not in valid Unicode range."sv));
     // Get the level 2 item from the highest 12 bit (8 - 19) of ch.

+ 18 - 11
src/Natsu.Compiler/ILImporter.cs

@@ -890,7 +890,7 @@ namespace Natsu.Compiler
             {
                 var genArgs = gen.GenericArguments;
                 tGen.AddRange(genArgs);
-                expr = $"{TypeUtils.EscapeTypeName(member.DeclaringType)}::{TypeUtils.EscapeMethodName(member, hasParamType: false)}<{string.Join(", ", gen.GenericArguments.Select(x => TypeUtils.EscapeTypeName(x)))}>({string.Join(", ", para.Select((x, i) => CastExpression(x.destType, x.src, genArgs)))})";
+                expr = $"{TypeUtils.EscapeTypeName(member.DeclaringType)}::{TypeUtils.EscapeMethodName(member, hasParamType: false)}<{string.Join(", ", gen.GenericArguments.Select(x => TypeUtils.EscapeTypeName(x, cppBasicType: true)))}>({string.Join(", ", para.Select((x, i) => CastExpression(x.destType, x.src, genArgs)))})";
             }
             else
             {
@@ -1030,7 +1030,7 @@ namespace Natsu.Compiler
             var v2 = Stack.Pop();
             var v1 = Stack.Pop();
             var nextOp = (Instruction)Op.Operand;
-            Writer.Ident(Ident).WriteLine($"if (::natsu::ops::{op}_({v1.Expression}, {v2.Expression}).istrue())");
+            Writer.Ident(Ident).WriteLine($"if (::natsu::ops::{op}_({v1.Expression}, {v2.Expression}))");
             Writer.Ident(Ident + 1).WriteLine($"goto {ILUtils.GetLabel(Method, nextOp, Block)};");
             Writer.Ident(Ident).WriteLine("else");
             Writer.Ident(Ident + 1).WriteLine($"goto {ILUtils.GetFallthroughLabel(Method, Op, Block)};");
@@ -1040,7 +1040,7 @@ namespace Natsu.Compiler
         {
             var v1 = Stack.Pop();
             var nextOp = (Instruction)Op.Operand;
-            Writer.Ident(Ident).WriteLine($"if ({op}{v1.Expression}.istrue())");
+            Writer.Ident(Ident).WriteLine($"if ({op}{v1.Expression})");
             Writer.Ident(Ident + 1).WriteLine($"goto {ILUtils.GetLabel(Method, nextOp, Block)};");
             Writer.Ident(Ident).WriteLine("else");
             Writer.Ident(Ident + 1).WriteLine($"goto {ILUtils.GetFallthroughLabel(Method, Op, Block)};");
@@ -1080,8 +1080,15 @@ namespace Natsu.Compiler
             var target = Stack.Pop();
             var field = (IField)Op.Operand;
             var thisType = TypeUtils.ThisType(field.DeclaringType);
-            string expr = $"::natsu::stack_to<{TypeUtils.EscapeVariableTypeName(thisType)}>({target.Expression})->" + TypeUtils.EscapeIdentifier(field.Name);
-            Stack.Push(StackTypeCode.Ref, $"::natsu::ops::ref({expr})");
+            if (TypeUtils.IsCppBasicType(field.DeclaringType))
+            {
+                Stack.Push(StackTypeCode.Ref, $"::natsu::ops::ref({target.Expression})");
+            }
+            else
+            {
+                string expr = $"::natsu::stack_to<{TypeUtils.EscapeVariableTypeName(thisType)}>({target.Expression})->" + TypeUtils.EscapeIdentifier(field.Name);
+                Stack.Push(StackTypeCode.Ref, $"::natsu::ops::ref({expr})");
+            }
         }
 
         public void Ldsflda()
@@ -1144,7 +1151,7 @@ namespace Natsu.Compiler
 
             para.Reverse();
             var genSig = member.DeclaringType.TryGetGenericInstSig();
-            var expr = $"::natsu::ops::newobj<{TypeUtils.EscapeTypeName(member.DeclaringType)}>({string.Join(", ", para.Select(x => CastExpression(x.destType, x.src, genSig?.GenericArguments)))})";
+            var expr = $"::natsu::ops::newobj<{TypeUtils.EscapeTypeName(member.DeclaringType, cppBasicType: true)}>({string.Join(", ", para.Select(x => CastExpression(x.destType, x.src, genSig?.GenericArguments)))})";
             Stack.Push(StackTypeCode.O, expr);
         }
 
@@ -1166,35 +1173,35 @@ namespace Natsu.Compiler
         public void Ldtoken()
         {
             var type = (ITypeDefOrRef)Op.Operand;
-            Stack.Push(new StackType { Code = StackTypeCode.Runtime, Name = "::System_Private_CorLib::System::RuntimeTypeHandle" }, $"::natsu::ops::ldtoken_type<{TypeUtils.EscapeTypeName(type)}>()");
+            Stack.Push(new StackType { Code = StackTypeCode.Runtime, Name = "::System_Private_CoreLib::System::RuntimeTypeHandle" }, $"::natsu::ops::ldtoken_type<{TypeUtils.EscapeTypeName(type)}>()");
         }
 
         public void Isinst()
         {
             var type = (ITypeDefOrRef)Op.Operand;
             var obj = Stack.Pop();
-            Stack.Push(StackTypeCode.O, $"::natsu::ops::isinst<{TypeUtils.EscapeTypeName(type)}>({obj.Expression})");
+            Stack.Push(StackTypeCode.O, $"::natsu::ops::isinst<{TypeUtils.EscapeTypeName(type, cppBasicType: true)}>({obj.Expression})");
         }
 
         public void Unbox_Any()
         {
             var type = (ITypeDefOrRef)Op.Operand;
             var obj = Stack.Pop();
-            Stack.Push(StackTypeCode.O, $"::natsu::ops::unbox_any<{TypeUtils.EscapeTypeName(type)}>({obj.Expression})");
+            Stack.Push(StackTypeCode.O, $"::natsu::ops::unbox_any<{TypeUtils.EscapeTypeName(type, cppBasicType: true)}>({obj.Expression})");
         }
 
         public void Unbox()
         {
             var type = (ITypeDefOrRef)Op.Operand;
             var obj = Stack.Pop();
-            Stack.Push(StackTypeCode.Ref, $"::natsu::ops::unbox<{TypeUtils.EscapeTypeName(type)}>({obj.Expression})");
+            Stack.Push(StackTypeCode.Ref, $"::natsu::ops::unbox<{TypeUtils.EscapeTypeName(type, cppBasicType: true)}>({obj.Expression})");
         }
 
         public void Castclass()
         {
             var type = (ITypeDefOrRef)Op.Operand;
             var obj = Stack.Pop();
-            Stack.Push(StackTypeCode.O, $"::natsu::ops::castclass<{TypeUtils.EscapeTypeName(type)}>({obj.Expression})");
+            Stack.Push(StackTypeCode.O, $"::natsu::ops::castclass<{TypeUtils.EscapeTypeName(type, cppBasicType: true)}>({obj.Expression})");
         }
 
         public void Ldlen()

+ 58 - 45
src/Natsu.Compiler/Program.cs

@@ -18,14 +18,15 @@ namespace Natsu.Compiler
             @"..\..\..\..\..\out\bin\netcoreapp3.0\Chino.Core.dll",
             //@"..\..\..\..\..\out\bin\netcoreapp3.0\Chino.Chip.K210.dll",
             @"..\..\..\..\..\out\bin\netcoreapp3.0\Chino.Chip.Emulator.dll",
-            @"..\..\..\..\..\out\bin\netcoreapp3.0\System.Private.CorLib.dll",
-            //@"..\..\..\..\..\out\bin\netcoreapp3.0\System.Collections.dll",
+            //@"..\..\..\..\..\out\bin\netcoreapp3.0\System.Private.CoreLib.dll",
+            @"..\..\..\..\..\out\bin\netcoreapp3.0\System.Collections.dll",
             //@"..\..\..\..\..\out\bin\netcoreapp3.0\System.Memory.dll",
             //@"..\..\..\..\..\out\bin\netcoreapp3.0\System.Runtime.dll",
             //@"..\..\..\..\..\out\bin\netcoreapp3.0\System.Runtime.Extensions.dll",
             //@"..\..\..\..\..\out\bin\netcoreapp3.0\System.Diagnostics.Debug.dll",
             //@"..\..\..\..\..\out\bin\netcoreapp3.0\System.Runtime.InteropServices.dll",
             //@"..\..\..\..\..\out\bin\netcoreapp3.0\System.Threading.dll",
+            //@"..\..\..\..\..\out\bin\netcoreapp3.0\System.Threading.Thread.dll",
             //Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), @".nuget\packages\bitfields\0.1.0\lib\netstandard1.0\BitFields.dll")
         };
 
@@ -76,7 +77,7 @@ namespace Natsu.Compiler
             {
                 writer.WriteLine("// Generated by natsu clr compiler.");
                 writer.WriteLine("#pragma once");
-                if (_module.Assembly.Name == "System.Private.CorLib")
+                if (_module.Assembly.Name == "System.Private.CoreLib")
                 {
                     writer.WriteLine("#include <natsu.typedef.h>");
                 }
@@ -100,7 +101,7 @@ namespace Natsu.Compiler
                 writer.WriteLine("}");
                 writer.WriteLine();
 
-                if (_module.Assembly.Name == "System.Private.CorLib")
+                if (_module.Assembly.Name == "System.Private.CoreLib")
                 {
                     writer.WriteLine("#include <natsu.runtime.h>");
                     writer.WriteLine();
@@ -120,7 +121,6 @@ namespace Natsu.Compiler
                     writerSrc.WriteLine($"namespace {TypeUtils.EscapeModuleName(_module)}");
                     writerSrc.WriteLine("{");
                     WriteTypeMethodsBody(writerSrc, false);
-                    WriteConstantStringFields(writerSrc);
                     writerSrc.WriteLine("}");
                 }
 
@@ -153,27 +153,12 @@ namespace Natsu.Compiler
         {
             for (int i = 0; i < _userStrings.Count; i++)
             {
-                writer.Ident(1).WriteLine($"static const constexpr natsu::static_object<::System_Private_CorLib::System::String, natsu::string_literal<{_userStrings[i].Length}>> user_string_{i}(uR\"NS({_userStrings[i]})NS\"sv);");
+                writer.Ident(1).WriteLine($"static const constexpr natsu::static_object<::System_Private_CoreLib::System::String, natsu::string_literal<{_userStrings[i].Length}>> user_string_{i}(uR\"NS({_userStrings[i]})NS\"sv);");
             }
 
             writer.WriteLine();
         }
 
-        private void WriteConstantStringFields(StreamWriter writer)
-        {
-            foreach (var type in _sortedTypeDescs)
-            {
-                if (!type.TypeDef.IsEnum)
-                {
-                    foreach (var field in type.TypeDef.Fields)
-                    {
-                        if (field.HasConstant && field.ElementType == ElementType.String)
-                            WriteConstantStringField(writer, 0, field);
-                    }
-                }
-            }
-        }
-
         private void SortTypes()
         {
             foreach (var type in _typeDescs.Values)
@@ -266,7 +251,6 @@ namespace Natsu.Compiler
                     case ElementType.CModReqd:
                     case ElementType.Object:
                     case ElementType.Class:
-                        break;
                     case ElementType.Boolean:
                     case ElementType.Char:
                     case ElementType.I1:
@@ -279,6 +263,7 @@ namespace Natsu.Compiler
                     case ElementType.U8:
                     case ElementType.R4:
                     case ElementType.R8:
+                        break;
                     case ElementType.String:
                     case ElementType.I:
                     case ElementType.U:
@@ -312,7 +297,7 @@ namespace Natsu.Compiler
 
         private void AddTypeRef(TypeDesc declareDesc, TypeDef typeDef, bool force)
         {
-            if (typeDef != null && (force || typeDef.IsValueType))
+            if (typeDef != null && (force || typeDef.IsValueType || typeDef.ToTypeSig().ElementType == ElementType.String))
             {
                 if (_typeDescs.TryGetValue(typeDef, out var targetDesc))
                 {
@@ -454,6 +439,22 @@ namespace Natsu.Compiler
             }
 
             writer.Ident(ident).WriteLine("{");
+            // ctor
+            if (type.TypeDef.IsExplicitLayout)
+            {
+                writer.Ident(ident + 1).WriteLine($"{type.Name}() = default;");
+                writer.WriteLine();
+                writer.Ident(ident + 1).WriteLine($"{type.Name}(const {type.Name} &other) noexcept");
+                writer.Ident(ident + 1).WriteLine("{");
+                writer.Ident(ident + 2).WriteLine($"std::memcpy(this, &other, sizeof({type.Name}));");
+                writer.Ident(ident + 1).WriteLine("}");
+                writer.WriteLine();
+                writer.Ident(ident + 1).WriteLine($"{type.Name}({type.Name} &&other) noexcept");
+                writer.Ident(ident + 1).WriteLine("{");
+                writer.Ident(ident + 2).WriteLine($"std::memcpy(this, &other, sizeof({type.Name}));");
+                writer.Ident(ident + 1).WriteLine("}");
+                writer.WriteLine();
+            }
 
             // TypeInfo
             WriteTypeInfo(writer, ident + 1, type);
@@ -466,9 +467,9 @@ namespace Natsu.Compiler
             string fieldSize = "0";
             foreach (var field in type.TypeDef.Fields)
             {
-                if (field.HasConstant && field.ElementType != ElementType.String)
+                if (field.HasConstant)
                     WriteConstantField(writer, ident + 1, field);
-                else if (!field.IsStatic || field.ElementType == ElementType.String)
+                else if (!field.IsStatic)
                     WriteField(writer, ident + 1, field);
                 else
                     hasStaticMember = true;
@@ -543,7 +544,6 @@ namespace Natsu.Compiler
         {
             writer.Ident(ident).WriteLine($"struct TypeInfo");
             writer.Ident(ident).WriteLine("{");
-
             // IsValueType
             writer.Ident(ident + 1).WriteLine($"static constexpr bool IsValueType = {type.TypeDef.IsValueType.ToString().ToLower()};");
             // IsEnum
@@ -557,27 +557,34 @@ namespace Natsu.Compiler
             writer.Ident(ident).Write($"struct VTable");
             if (!type.TypeDef.IsInterface)
             {
-                writer.Write(" : public ::natsu::vtable_class<");
+                var baseSb = new StringBuilder();
+                baseSb.Append("::natsu::vtable_class<");
                 var baseType = GetBaseType(type.TypeDef);
                 if (baseType == null)
-                    writer.Write("natsu::vtable_t");
+                    baseSb.Append("natsu::vtable_t");
                 else
-                    writer.Write($"typename {TypeUtils.EscapeTypeName(baseType)}::VTable");
+                    baseSb.Append($"typename {TypeUtils.EscapeTypeName(baseType, cppBasicType: true)}::VTable");
 
                 foreach (var iface in type.TypeDef.Interfaces)
                 {
                     var ifaceType = iface.Interface;
-                    writer.Write($", typename {TypeUtils.EscapeTypeName(ifaceType)}::VTable");
+                    baseSb.Append($", typename {TypeUtils.EscapeTypeName(ifaceType, cppBasicType: true)}::VTable");
                 }
 
-                writer.WriteLine(">");
+                baseSb.Append(">");
+
+                writer.WriteLine($": public {baseSb}");
+                writer.Ident(ident).WriteLine("{");
+                writer.Ident(ident + 1).WriteLine($"using base_t = {baseSb};");
+                writer.WriteLine();
             }
             else
             {
                 writer.WriteLine();
+
+                writer.Ident(ident).WriteLine("{");
             }
 
-            writer.Ident(ident).WriteLine("{");
             WriteVTableCtor(writer, type, ident + 1);
             writer.WriteLine();
 
@@ -650,11 +657,6 @@ namespace Natsu.Compiler
             writer.WriteLine();
         }
 
-        private void WriteConstantStringField(StreamWriter writer, int ident, FieldDef value)
-        {
-            writer.Ident(ident).WriteLine($"{TypeUtils.EscapeVariableTypeName(value.FieldType, value.DeclaringType)} {TypeUtils.EscapeTypeName(value.DeclaringType, hasModuleName: false)}::{TypeUtils.EscapeIdentifier(value.Name)} = ::natsu::load_string(uR\"NS({value.Constant.Value})NS\"sv);");
-        }
-
         private void WriteMethodDeclare(TextWriter writer, int ident, MethodDef method)
         {
             var methodGens = new List<string>();
@@ -682,7 +684,7 @@ namespace Natsu.Compiler
                 if (hasType)
                 {
                     if (isVTable && method.IsVirtual && param.IsHiddenThisParameter)
-                        writer.Write("::natsu::gc_obj_ref<::System_Private_CorLib::System::Object>");
+                        writer.Write("::natsu::gc_obj_ref<::System_Private_CoreLib::System::Object>");
                     else
                         writer.Write(TypeUtils.EscapeVariableTypeName(param.Type, hasGen: 1) + " ");
                 }
@@ -692,11 +694,11 @@ namespace Natsu.Compiler
                 {
                     if (method.DeclaringType.IsValueType)
                     {
-                        writer.Write($"::natsu::unbox_exact<{TypeUtils.EscapeTypeName(method.DeclaringType)}>({TypeUtils.EscapeIdentifier(paramName)})");
+                        writer.Write($"::natsu::unbox_exact<{TypeUtils.EscapeTypeName(method.DeclaringType, cppBasicType: true)}>({TypeUtils.EscapeIdentifier(paramName)})");
                     }
                     else
                     {
-                        writer.Write($"{TypeUtils.EscapeIdentifier(paramName)}.cast<{TypeUtils.EscapeTypeName(method.DeclaringType)}>()");
+                        writer.Write($"{TypeUtils.EscapeIdentifier(paramName)}.cast<{TypeUtils.EscapeTypeName(method.DeclaringType, cppBasicType: true)}>()");
                     }
                 }
                 else
@@ -715,7 +717,18 @@ namespace Natsu.Compiler
             if (value.IsStatic)
                 prefix = "static ";
 
-            writer.Ident(ident).WriteLine($"{prefix}constexpr {TypeUtils.GetConstantTypeName(value.ElementType)} {TypeUtils.EscapeIdentifier(value.Name)} = {TypeUtils.LiteralConstant(value.Constant.Value)};");
+            if (value.ElementType == ElementType.String)
+            {
+                var str = (string)value.Constant.Value;
+                writer.Ident(ident).WriteLine($"static const constexpr natsu::static_object<::System_Private_CoreLib::System::String, natsu::string_literal<{str.Length}>> _storage_{TypeUtils.EscapeIdentifier(value.Name)}{{uR\"NS({str})NS\"sv}};");
+
+                writer.Ident(ident).WriteLine($"inline {prefix}::natsu::gc_obj_ref<::System_Private_CoreLib::System::String> {TypeUtils.EscapeIdentifier(value.Name)} = _storage_{TypeUtils.EscapeIdentifier(value.Name)}.get();");
+
+            }
+            else
+            {
+                writer.Ident(ident).WriteLine($"{prefix}constexpr {TypeUtils.GetConstantTypeName(value.ElementType)} {TypeUtils.EscapeIdentifier(value.Name)} = {TypeUtils.LiteralConstant(value.Constant.Value)};");
+            }
         }
         #endregion
 
@@ -826,7 +839,7 @@ namespace Natsu.Compiler
                         {
                             foreach (var ov in method.Overrides)
                             {
-                                writer.Ident(ident + 1).Write(TypeUtils.EscapeTypeName(ov.MethodDeclaration.DeclaringType));
+                                writer.Ident(ident + 1).Write(TypeUtils.EscapeTypeName(ov.MethodDeclaration.DeclaringType, cppBasicType: true));
                                 writer.Write("::VTable::");
                                 writer.Write(TypeUtils.EscapeMethodName(ov.MethodDeclaration));
                                 writer.Write(" = ");
@@ -835,7 +848,7 @@ namespace Natsu.Compiler
                         }
                         else if (!method.IsNewSlot)
                         {
-                            writer.Ident(ident + 1).Write("override_vfunc");
+                            writer.Ident(ident + 1).Write("base_t::override_vfunc");
                             writer.Write("(R\"NS(" + method.Name + ")NS\", ");
                             writer.WriteLine("_imp_" + TypeUtils.EscapeMethodName(method) + ");");
                         }
@@ -992,7 +1005,7 @@ namespace Natsu.Compiler
                 }
                 else if (method.Name == "Invoke")
                 {
-                    writer.Ident(ident).Write($"typedef {TypeUtils.EscapeVariableTypeName(method.ReturnType)}(*method_t)(::natsu::gc_obj_ref<::System_Private_CorLib::System::Object>");
+                    writer.Ident(ident).Write($"typedef {TypeUtils.EscapeVariableTypeName(method.ReturnType)}(*method_t)(::natsu::gc_obj_ref<::System_Private_CoreLib::System::Object>");
                     foreach (var param in method.Parameters.Skip(1))
                         writer.Write(", " + TypeUtils.EscapeVariableTypeName(param.Type, hasGen: 1));
                     writer.WriteLine(");");
@@ -1014,7 +1027,7 @@ namespace Natsu.Compiler
                         writer.Ident(ident + 1).WriteLine($"{TypeUtils.EscapeVariableTypeName(method.ReturnType)} result;");
                     writer.Ident(ident + 1).WriteLine("for (auto d : *_this->_invocationList)");
                     writer.Ident(ident + 1).WriteLine("{");
-                    writer.Ident(ident + 2).WriteLine($"auto typed_d = d.cast<{TypeUtils.EscapeTypeName(method.DeclaringType)}>();");
+                    writer.Ident(ident + 2).WriteLine($"auto typed_d = d.template cast<{TypeUtils.EscapeTypeName(method.DeclaringType)}>();");
                     if (method.HasReturnType)
                         writer.Ident(ident + 2).Write($"result = reinterpret_cast<method_t>((intptr_t)typed_d->_methodPtr)(typed_d->_target");
                     else

+ 88 - 23
src/Natsu.Compiler/TypeUtils.cs

@@ -121,21 +121,21 @@ namespace Natsu.Compiler
             return type.ToTypeSig();
         }
 
-        public static string EscapeTypeName(TypeSig fieldType, TypeDef declaringType = null, int hasGen = 0, IList<TypeSig> genArgs = null)
+        public static string EscapeTypeName(TypeSig fieldType, TypeDef declaringType = null, int hasGen = 0, IList<TypeSig> genArgs = null, bool cppBasicType = false)
         {
             var sb = new StringBuilder();
-            EscapeTypeName(sb, fieldType, declaringType, hasGen, genArgs);
+            EscapeTypeName(sb, fieldType, declaringType, hasGen, genArgs, cppBasicType);
             return sb.ToString();
         }
 
         public static string EscapeVariableTypeName(TypeSig fieldType, TypeDef declaringType = null, int hasGen = 0, IList<TypeSig> genArgs = null)
         {
             if (IsValueType(fieldType))
-                return EscapeTypeName(fieldType, declaringType, hasGen, genArgs);
+                return EscapeTypeName(fieldType, declaringType, hasGen, genArgs, cppBasicType: true);
             else if (fieldType.IsGenericParameter)
-                return $"::natsu::variable_type_t<{EscapeTypeName(fieldType, declaringType, hasGen, genArgs)}>";
+                return $"::natsu::variable_type_t<{EscapeTypeName(fieldType, declaringType, hasGen, genArgs, cppBasicType: true)}>";
             else
-                return $"::natsu::gc_obj_ref<{EscapeTypeName(fieldType, declaringType, hasGen, genArgs)}>";
+                return $"::natsu::gc_obj_ref<{EscapeTypeName(fieldType, declaringType, hasGen, genArgs, cppBasicType: true)}>";
         }
 
         private static bool IsValueType(TypeSig type)
@@ -144,7 +144,7 @@ namespace Natsu.Compiler
             return type.IsValueType || type.IsByRef || type.IsPointer || (type.IsPinned && IsValueType(type.Next)) || (type.IsModifier && IsValueType(type.Next));
         }
 
-        public static void EscapeTypeName(StringBuilder sb, TypeSig cntSig, TypeDef declaringType = null, int hasGen = 0, IList<TypeSig> genArgs = null)
+        public static void EscapeTypeName(StringBuilder sb, TypeSig cntSig, TypeDef declaringType = null, int hasGen = 0, IList<TypeSig> genArgs = null, bool cppBasicType = false)
         {
             switch (cntSig.ElementType)
             {
@@ -173,7 +173,7 @@ namespace Natsu.Compiler
                                 if (declaringType != null && sig.TypeDef == declaringType)
                                     sb.Append(GetConstantTypeName(cntSig.ElementType));
                                 else
-                                    sb.Append(EscapeTypeName(sig.TypeDefOrRef, hasGen: hasGen-- > 0, genArgs: genArgs));
+                                    sb.Append(EscapeTypeName(sig.TypeDefOrRef, hasGen: hasGen-- > 0, genArgs: genArgs, cppBasicType: cppBasicType));
                                 break;
                             default:
                                 throw new NotSupportedException();
@@ -190,7 +190,7 @@ namespace Natsu.Compiler
                                 if (sig.IsPrimitive && declaringType != null && sig.TypeDef == declaringType)
                                     sb.Append(GetConstantTypeName(cntSig.ElementType));
                                 else
-                                    sb.Append(EscapeTypeName(sig.TypeDefOrRef, hasGen: hasGen-- > 0, genArgs: genArgs));
+                                    sb.Append(EscapeTypeName(sig.TypeDefOrRef, hasGen: hasGen-- > 0, genArgs: genArgs, cppBasicType: cppBasicType));
                                 break;
                             default:
                                 throw new NotSupportedException();
@@ -198,8 +198,8 @@ namespace Natsu.Compiler
                     }
                     break;
                 case ElementType.SZArray:
-                    sb.Append("::System_Private_CorLib::System::SZArray_1<");
-                    EscapeTypeName(sb, cntSig.Next, declaringType, genArgs: genArgs);
+                    sb.Append("::System_Private_CoreLib::System::SZArray_1<");
+                    EscapeTypeName(sb, cntSig.Next, declaringType, genArgs: genArgs, cppBasicType: true);
                     sb.Append(">");
                     break;
                 case ElementType.Var:
@@ -209,9 +209,9 @@ namespace Natsu.Compiler
                         {
                             var sig = genArgs.OfType<GenericSig>().FirstOrDefault(x => x.Number == var.Number);
                             if (sig != null)
-                                EscapeTypeName(sb, sig);
+                                EscapeTypeName(sb, sig, cppBasicType: true);
                             else
-                                EscapeTypeName(sb, genArgs[(int)var.Number]);
+                                EscapeTypeName(sb, genArgs[(int)var.Number], cppBasicType: true);
                         }
                         else
                         {
@@ -223,7 +223,7 @@ namespace Natsu.Compiler
                     {
                         var mvar = cntSig.ToGenericMVar();
                         if (genArgs != null)
-                            EscapeTypeName(sb, genArgs[(int)mvar.Number]);
+                            EscapeTypeName(sb, genArgs[(int)mvar.Number], cppBasicType: true);
                         else
                             sb.Append(mvar.GetName());
                     }
@@ -231,11 +231,11 @@ namespace Natsu.Compiler
                 case ElementType.GenericInst:
                     {
                         var sig = cntSig.ToGenericInstSig();
-                        sb.Append(EscapeTypeName(sig.GenericType.TypeDefOrRef, hasGen: false));
+                        sb.Append(EscapeTypeName(sig.GenericType.TypeDefOrRef, hasGen: false, cppBasicType: cppBasicType));
                         sb.Append("<");
                         for (int i = 0; i < sig.GenericArguments.Count; i++)
                         {
-                            EscapeTypeName(sb, sig.GenericArguments[i], null, genArgs: genArgs);
+                            EscapeTypeName(sb, sig.GenericArguments[i], null, genArgs: genArgs, cppBasicType: true);
                             if (i != sig.GenericArguments.Count - 1)
                                 sb.Append(", ");
                         }
@@ -253,19 +253,19 @@ namespace Natsu.Compiler
                     sb.Append(">");
                     break;
                 case ElementType.Pinned:
-                    EscapeTypeName(sb, cntSig.Next, declaringType, hasGen, genArgs);
+                    EscapeTypeName(sb, cntSig.Next, declaringType, hasGen, genArgs, cppBasicType: cppBasicType);
                     break;
                 case ElementType.CModReqd:
-                    EscapeTypeName(sb, cntSig.Next, declaringType, hasGen, genArgs);
+                    EscapeTypeName(sb, cntSig.Next, declaringType, hasGen, genArgs, cppBasicType: cppBasicType);
                     break;
                 default:
                     throw new NotSupportedException();
             }
         }
 
-        public static string EscapeTypeName(ITypeDefOrRef type, bool hasGen = true, bool hasModuleName = true, IList<TypeSig> genArgs = null)
+        public static string EscapeTypeName(ITypeDefOrRef type, bool hasGen = true, bool hasModuleName = true, IList<TypeSig> genArgs = null, bool cppBasicType = false)
         {
-            return EscapeTypeNameImpl(type, hasGen, hasModuleName, genArgs);
+            return EscapeTypeNameImpl(type, hasGen, hasModuleName, genArgs, cppBasicType);
         }
 
         public static string EscapeVariableTypeName(ITypeDefOrRef type, bool hasGen = true, bool hasModuleName = true, IList<TypeSig> genArgs = null)
@@ -284,16 +284,81 @@ namespace Natsu.Compiler
             return EscapeIdentifier(name.Split('.').Last());
         }
 
-        private static string EscapeTypeNameImpl(ITypeDefOrRef type, bool hasGen, bool hasModuleName, IList<TypeSig> genArgs = null)
+        public static bool IsCppBasicType(ITypeDefOrRef type)
+        {
+            switch (type.ToTypeSig().ElementType)
+            {
+                case ElementType.Boolean:
+                case ElementType.Char:
+                case ElementType.I1:
+                case ElementType.U1:
+                case ElementType.I2:
+                case ElementType.U2:
+                case ElementType.I4:
+                case ElementType.U4:
+                case ElementType.I8:
+                case ElementType.U8:
+                case ElementType.R4:
+                case ElementType.R8:
+                    return true;
+                    //case ElementType.I:
+                    //case ElementType.U:
+            }
+
+            return false;
+        }
+
+        private static string EscapeTypeNameImpl(ITypeDefOrRef type, bool hasGen, bool hasModuleName, IList<TypeSig> genArgs = null, bool cppBasicType = false)
         {
             if (type is TypeSpec typeSpec)
             {
-                return EscapeTypeName(typeSpec.TypeSig, null);
+                return EscapeTypeName(typeSpec.TypeSig, null, cppBasicType: cppBasicType);
+            }
+
+            if (cppBasicType && type.IsPrimitive)
+            {
+                switch (type.ToTypeSig().ElementType)
+                {
+                    case ElementType.Boolean:
+                        return "bool";
+                    case ElementType.Char:
+                        return "char16_t";
+                    case ElementType.I1:
+                        return "int8_t";
+                    case ElementType.U1:
+                        return "uint8_t";
+                    case ElementType.I2:
+                        return "int16_t";
+                    case ElementType.U2:
+                        return "uint16_t";
+                    case ElementType.I4:
+                        return "int32_t";
+                    case ElementType.U4:
+                        return "uint32_t";
+                    case ElementType.I8:
+                        return "int64_t";
+                    case ElementType.U8:
+                        return "uint64_t";
+                    case ElementType.R4:
+                        return "float";
+                    case ElementType.R8:
+                        return "double";
+                        //case ElementType.I:
+                        //    return "intptr_t";
+                        //case ElementType.U:
+                        //    return "uintptr_t";
+                }
             }
 
             var sb = new StringBuilder();
             if (hasModuleName)
-                sb.Append("::" + EscapeModuleName(type.DefinitionAssembly) + "::");
+            {
+                var moduleName = EscapeModuleName(type.DefinitionAssembly);
+                if (moduleName == "mscorlib")
+                    moduleName = "System_Private_CoreLib";
+                sb.Append("::" + moduleName + "::");
+            }
+
             var nss = TypeUtils.GetNamespace(type).Split('.', StringSplitOptions.RemoveEmptyEntries)
                 .Select(EscapeNamespaceName).ToList();
             foreach (var ns in nss)
@@ -572,7 +637,7 @@ namespace Natsu.Compiler
                 case ElementType.R8:
                     return "double";
                 case ElementType.String:
-                    return "::System_Private_CorLib::System::String";
+                    return "::System_Private_CoreLib::System::String";
                 case ElementType.I:
                     return "intptr_t";
                 case ElementType.U:

+ 3 - 2
src/ResX2CS/Program.cs

@@ -9,10 +9,11 @@ namespace ResX2CS
     {
         static void Main(string[] args)
         {
-            var path = @"..\..\..\..\System.Private.CorLib\Resources\Strings.resx";
+            var assembly = "System.Collections";
+            var path = @"..\..\..\..\" + assembly + @"\Resources\Strings.resx";
             var xml = XDocument.Load(path);
             var datas = xml.Root.Nodes().OfType<XElement>().Where(x => x.Name == "data").ToList();
-            using (var cs = new StreamWriter(File.Open(@"..\..\..\..\System.Private.CorLib\Resources\Strings.Designer.cs", FileMode.Create)))
+            using (var cs = new StreamWriter(File.Open(@"..\..\..\..\" + assembly + @"\Resources\Strings.Designer.cs", FileMode.Create)))
             {
                 StreamWriter Ident(int n)
                 {

+ 1 - 2
src/ResX2CS/ResX2CS.csproj

@@ -1,8 +1,7 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
 
   <PropertyGroup>
     <OutputType>Exe</OutputType>
     <TargetFramework>netcoreapp3.0</TargetFramework>
   </PropertyGroup>
-
 </Project>

+ 34 - 0
src/System.Collections/ICollectionDebugView.cs

@@ -0,0 +1,34 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Diagnostics;
+
+namespace System.Collections.Generic
+{
+    internal sealed class ICollectionDebugView<T>
+    {
+        private readonly ICollection<T> _collection;
+
+        public ICollectionDebugView(ICollection<T> collection)
+        {
+            if (collection == null)
+            {
+                throw new ArgumentNullException(nameof(collection));
+            }
+
+            _collection = collection;
+        }
+
+        [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
+        public T[] Items
+        {
+            get
+            {
+                T[] items = new T[_collection.Count];
+                _collection.CopyTo(items, 0);
+                return items;
+            }
+        }
+    }
+}

+ 515 - 0
src/System.Collections/LinkedList.cs

@@ -0,0 +1,515 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
+using System.Runtime.Serialization;
+
+namespace System.Collections.Generic
+{
+    [DebuggerTypeProxy(typeof(ICollectionDebugView<>))]
+    [DebuggerDisplay("Count = {Count}")]
+    [Serializable]
+    [System.Runtime.CompilerServices.TypeForwardedFrom("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
+    public class LinkedList<T> : ICollection<T>, IReadOnlyCollection<T>
+    {
+        // This LinkedList is a doubly-Linked circular list.
+        internal LinkedListNode<T> head;
+        internal int count;
+        internal int version;
+
+        // names for serialization
+        private const string VersionName = "Version"; // Do not rename (binary serialization)
+        private const string CountName = "Count"; // Do not rename (binary serialization)
+        private const string ValuesName = "Data"; // Do not rename (binary serialization)
+
+        public LinkedList()
+        {
+        }
+
+        public LinkedList(IEnumerable<T> collection)
+        {
+            if (collection == null)
+            {
+                throw new ArgumentNullException(nameof(collection));
+            }
+
+            foreach (T item in collection)
+            {
+                AddLast(item);
+            }
+        }
+
+        public int Count
+        {
+            get { return count; }
+        }
+
+        public LinkedListNode<T> First
+        {
+            get { return head; }
+        }
+
+        public LinkedListNode<T> Last
+        {
+            get { return head == null ? null : head.prev; }
+        }
+
+        bool ICollection<T>.IsReadOnly
+        {
+            get { return false; }
+        }
+
+        void ICollection<T>.Add(T value)
+        {
+            AddLast(value);
+        }
+
+        public LinkedListNode<T> AddAfter(LinkedListNode<T> node, T value)
+        {
+            ValidateNode(node);
+            LinkedListNode<T> result = new LinkedListNode<T>(node.list, value);
+            InternalInsertNodeBefore(node.next, result);
+            return result;
+        }
+
+        public void AddAfter(LinkedListNode<T> node, LinkedListNode<T> newNode)
+        {
+            ValidateNode(node);
+            ValidateNewNode(newNode);
+            InternalInsertNodeBefore(node.next, newNode);
+            newNode.list = this;
+        }
+
+        public LinkedListNode<T> AddBefore(LinkedListNode<T> node, T value)
+        {
+            ValidateNode(node);
+            LinkedListNode<T> result = new LinkedListNode<T>(node.list, value);
+            InternalInsertNodeBefore(node, result);
+            if (node == head)
+            {
+                head = result;
+            }
+            return result;
+        }
+
+        public void AddBefore(LinkedListNode<T> node, LinkedListNode<T> newNode)
+        {
+            ValidateNode(node);
+            ValidateNewNode(newNode);
+            InternalInsertNodeBefore(node, newNode);
+            newNode.list = this;
+            if (node == head)
+            {
+                head = newNode;
+            }
+        }
+
+        public LinkedListNode<T> AddFirst(T value)
+        {
+            LinkedListNode<T> result = new LinkedListNode<T>(this, value);
+            if (head == null)
+            {
+                InternalInsertNodeToEmptyList(result);
+            }
+            else
+            {
+                InternalInsertNodeBefore(head, result);
+                head = result;
+            }
+            return result;
+        }
+
+        public void AddFirst(LinkedListNode<T> node)
+        {
+            ValidateNewNode(node);
+
+            if (head == null)
+            {
+                InternalInsertNodeToEmptyList(node);
+            }
+            else
+            {
+                InternalInsertNodeBefore(head, node);
+                head = node;
+            }
+            node.list = this;
+        }
+
+        public LinkedListNode<T> AddLast(T value)
+        {
+            LinkedListNode<T> result = new LinkedListNode<T>(this, value);
+            if (head == null)
+            {
+                InternalInsertNodeToEmptyList(result);
+            }
+            else
+            {
+                InternalInsertNodeBefore(head, result);
+            }
+            return result;
+        }
+
+        public void AddLast(LinkedListNode<T> node)
+        {
+            ValidateNewNode(node);
+
+            if (head == null)
+            {
+                InternalInsertNodeToEmptyList(node);
+            }
+            else
+            {
+                InternalInsertNodeBefore(head, node);
+            }
+            node.list = this;
+        }
+
+        public void Clear()
+        {
+            LinkedListNode<T> current = head;
+            while (current != null)
+            {
+                LinkedListNode<T> temp = current;
+                current = current.Next;   // use Next the instead of "next", otherwise it will loop forever
+                temp.Invalidate();
+            }
+
+            head = null;
+            count = 0;
+            version++;
+        }
+
+        public bool Contains(T value)
+        {
+            return Find(value) != null;
+        }
+
+        public void CopyTo(T[] array, int index)
+        {
+            if (array == null)
+            {
+                throw new ArgumentNullException(nameof(array));
+            }
+
+            if (index < 0)
+            {
+                throw new ArgumentOutOfRangeException(nameof(index), index, SR.ArgumentOutOfRange_NeedNonNegNum);
+            }
+
+            if (index > array.Length)
+            {
+                throw new ArgumentOutOfRangeException(nameof(index), index, SR.ArgumentOutOfRange_BiggerThanCollection);
+            }
+
+            if (array.Length - index < Count)
+            {
+                throw new ArgumentException(SR.Arg_InsufficientSpace);
+            }
+
+            LinkedListNode<T> node = head;
+            if (node != null)
+            {
+                do
+                {
+                    array[index++] = node.item;
+                    node = node.next;
+                } while (node != head);
+            }
+        }
+
+        public LinkedListNode<T> Find(T value)
+        {
+            LinkedListNode<T> node = head;
+            EqualityComparer<T> c = EqualityComparer<T>.Default;
+            if (node != null)
+            {
+                if (value != null)
+                {
+                    do
+                    {
+                        if (c.Equals(node.item, value))
+                        {
+                            return node;
+                        }
+                        node = node.next;
+                    } while (node != head);
+                }
+                else
+                {
+                    do
+                    {
+                        if (node.item == null)
+                        {
+                            return node;
+                        }
+                        node = node.next;
+                    } while (node != head);
+                }
+            }
+            return null;
+        }
+
+        public LinkedListNode<T> FindLast(T value)
+        {
+            if (head == null) return null;
+
+            LinkedListNode<T> last = head.prev;
+            LinkedListNode<T> node = last;
+            EqualityComparer<T> c = EqualityComparer<T>.Default;
+            if (node != null)
+            {
+                if (value != null)
+                {
+                    do
+                    {
+                        if (c.Equals(node.item, value))
+                        {
+                            return node;
+                        }
+
+                        node = node.prev;
+                    } while (node != last);
+                }
+                else
+                {
+                    do
+                    {
+                        if (node.item == null)
+                        {
+                            return node;
+                        }
+                        node = node.prev;
+                    } while (node != last);
+                }
+            }
+            return null;
+        }
+
+        public Enumerator GetEnumerator()
+        {
+            return new Enumerator(this);
+        }
+
+        IEnumerator<T> IEnumerable<T>.GetEnumerator()
+        {
+            return GetEnumerator();
+        }
+
+        public bool Remove(T value)
+        {
+            LinkedListNode<T> node = Find(value);
+            if (node != null)
+            {
+                InternalRemoveNode(node);
+                return true;
+            }
+            return false;
+        }
+
+        public void Remove(LinkedListNode<T> node)
+        {
+            ValidateNode(node);
+            InternalRemoveNode(node);
+        }
+
+        public void RemoveFirst()
+        {
+            if (head == null) { throw new InvalidOperationException(SR.LinkedListEmpty); }
+            InternalRemoveNode(head);
+        }
+
+        public void RemoveLast()
+        {
+            if (head == null) { throw new InvalidOperationException(SR.LinkedListEmpty); }
+            InternalRemoveNode(head.prev);
+        }
+
+        private void InternalInsertNodeBefore(LinkedListNode<T> node, LinkedListNode<T> newNode)
+        {
+            newNode.next = node;
+            newNode.prev = node.prev;
+            node.prev.next = newNode;
+            node.prev = newNode;
+            version++;
+            count++;
+        }
+
+        private void InternalInsertNodeToEmptyList(LinkedListNode<T> newNode)
+        {
+            Debug.Assert(head == null && count == 0, "LinkedList must be empty when this method is called!");
+            newNode.next = newNode;
+            newNode.prev = newNode;
+            head = newNode;
+            version++;
+            count++;
+        }
+
+        internal void InternalRemoveNode(LinkedListNode<T> node)
+        {
+            Debug.Assert(node.list == this, "Deleting the node from another list!");
+            Debug.Assert(head != null, "This method shouldn't be called on empty list!");
+            if (node.next == node)
+            {
+                Debug.Assert(count == 1 && head == node, "this should only be true for a list with only one node");
+                head = null;
+            }
+            else
+            {
+                node.next.prev = node.prev;
+                node.prev.next = node.next;
+                if (head == node)
+                {
+                    head = node.next;
+                }
+            }
+            node.Invalidate();
+            count--;
+            version++;
+        }
+
+        internal void ValidateNewNode(LinkedListNode<T> node)
+        {
+            if (node == null)
+            {
+                throw new ArgumentNullException(nameof(node));
+            }
+
+            if (node.list != null)
+            {
+                throw new InvalidOperationException(SR.LinkedListNodeIsAttached);
+            }
+        }
+
+        internal void ValidateNode(LinkedListNode<T> node)
+        {
+            if (node == null)
+            {
+                throw new ArgumentNullException(nameof(node));
+            }
+
+            if (node.list != this)
+            {
+                throw new InvalidOperationException(SR.ExternalLinkedListNode);
+            }
+        }
+
+        [SuppressMessage("Microsoft.Performance", "CA1815:OverrideEqualsAndOperatorEqualsOnValueTypes", Justification = "not an expected scenario")]
+        public struct Enumerator : IEnumerator<T>
+        {
+            private LinkedList<T> _list;
+            private LinkedListNode<T> _node;
+            private int _version;
+            private T _current;
+            private int _index;
+
+            const string LinkedListName = "LinkedList";
+            const string CurrentValueName = "Current";
+            const string VersionName = "Version";
+            const string IndexName = "Index";
+
+            internal Enumerator(LinkedList<T> list)
+            {
+                _list = list;
+                _version = list.version;
+                _node = list.head;
+                _current = default(T);
+                _index = 0;
+            }
+
+            public T Current
+            {
+                get { return _current; }
+            }
+
+            public bool MoveNext()
+            {
+                if (_version != _list.version)
+                {
+                    throw new InvalidOperationException(SR.InvalidOperation_EnumFailedVersion);
+                }
+
+                if (_node == null)
+                {
+                    _index = _list.Count + 1;
+                    return false;
+                }
+
+                ++_index;
+                _current = _node.item;
+                _node = _node.next;
+                if (_node == _list.head)
+                {
+                    _node = null;
+                }
+                return true;
+            }
+
+            public void Reset()
+            {
+                if (_version != _list.version)
+                {
+                    throw new InvalidOperationException(SR.InvalidOperation_EnumFailedVersion);
+                }
+
+                _current = default(T);
+                _node = _list.head;
+                _index = 0;
+            }
+
+            public void Dispose()
+            {
+            }
+        }
+    }
+
+    // Note following class is not serializable since we customized the serialization of LinkedList. 
+    public sealed class LinkedListNode<T>
+    {
+        internal LinkedList<T> list;
+        internal LinkedListNode<T> next;
+        internal LinkedListNode<T> prev;
+        internal T item;
+
+        public LinkedListNode(T value)
+        {
+            item = value;
+        }
+
+        internal LinkedListNode(LinkedList<T> list, T value)
+        {
+            this.list = list;
+            item = value;
+        }
+
+        public LinkedList<T> List
+        {
+            get { return list; }
+        }
+
+        public LinkedListNode<T> Next
+        {
+            get { return next == null || next == list.head ? null : next; }
+        }
+
+        public LinkedListNode<T> Previous
+        {
+            get { return prev == null || this == list.head ? null : prev; }
+        }
+
+        public T Value
+        {
+            get { return item; }
+            set { item = value; }
+        }
+
+        internal void Invalidate()
+        {
+            list = null;
+            next = null;
+            prev = null;
+        }
+    }
+}
+

+ 42 - 0
src/System.Collections/Resources/Strings.Designer.cs

@@ -0,0 +1,42 @@
+namespace System
+{
+    internal static partial class SR
+    {
+        public static string Arg_NonZeroLowerBound => @"The lower bound of target array must be zero.";
+        public static string Arg_WrongType => @"The value '{0}' is not of type '{1}' and cannot be used in this generic collection.";
+        public static string Arg_ArrayPlusOffTooSmall => @"Destination array is not long enough to copy all the items in the collection. Check array index and length.";
+        public static string ArgumentOutOfRange_NeedNonNegNum => @"Non-negative number required.";
+        public static string ArgumentOutOfRange_SmallCapacity => @"capacity was less than the current size.";
+        public static string Argument_InvalidOffLen => @"Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.";
+        public static string Argument_AddingDuplicate => @"An item with the same key has already been added. Key: {0}";
+        public static string InvalidOperation_ConcurrentOperationsNotSupported => @"Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.";
+        public static string InvalidOperation_EmptyQueue => @"Queue empty.";
+        public static string InvalidOperation_EnumOpCantHappen => @"Enumeration has either not started or has already finished.";
+        public static string InvalidOperation_EnumFailedVersion => @"Collection was modified; enumeration operation may not execute.";
+        public static string InvalidOperation_EmptyStack => @"Stack empty.";
+        public static string InvalidOperation_EnumNotStarted => @"Enumeration has not started. Call MoveNext.";
+        public static string InvalidOperation_EnumEnded => @"Enumeration already finished.";
+        public static string NotSupported_KeyCollectionSet => @"Mutating a key collection derived from a dictionary is not allowed.";
+        public static string NotSupported_ValueCollectionSet => @"Mutating a value collection derived from a dictionary is not allowed.";
+        public static string Arg_ArrayLengthsDiffer => @"Array lengths must be the same.";
+        public static string Arg_BitArrayTypeUnsupported => @"Only supported array types for CopyTo on BitArrays are Boolean[], Int32[] and Byte[].";
+        public static string Arg_HSCapacityOverflow => @"HashSet capacity is too big.";
+        public static string Arg_HTCapacityOverflow => @"Hashtable's capacity overflowed and went negative. Check load factor, capacity and the current size of the table.";
+        public static string Arg_InsufficientSpace => @"Insufficient space in the target location to copy the information.";
+        public static string Arg_RankMultiDimNotSupported => @"Only single dimensional arrays are supported for the requested action.";
+        public static string Argument_ArrayTooLarge => @"The input array length must not exceed Int32.MaxValue / {0}. Otherwise BitArray.Length would exceed Int32.MaxValue.";
+        public static string Argument_InvalidArrayType => @"Target array type is not compatible with the type of items in the collection.";
+        public static string ArgumentOutOfRange_BiggerThanCollection => @"Must be less than or equal to the size of the collection.";
+        public static string ArgumentOutOfRange_Index => @"Index was out of range. Must be non-negative and less than the size of the collection.";
+        public static string ExternalLinkedListNode => @"The LinkedList node does not belong to current LinkedList.";
+        public static string LinkedListEmpty => @"The LinkedList is empty.";
+        public static string LinkedListNodeIsAttached => @"The LinkedList node already belongs to a LinkedList.";
+        public static string NotSupported_SortedListNestedWrite => @"This operation is not supported on SortedList nested types because they require modifying the original SortedList.";
+        public static string SortedSet_LowerValueGreaterThanUpperValue => @"Must be less than or equal to upperValue.";
+        public static string Serialization_InvalidOnDeser => @"OnDeserialization method was called while the object was not being deserialized.";
+        public static string Serialization_MismatchedCount => @"The serialized Count information doesn't match the number of items.";
+        public static string Serialization_MissingKeys => @"The keys for this dictionary are missing.";
+        public static string Serialization_MissingValues => @"The values for this dictionary are missing.";
+        public static string Arg_KeyNotFoundWithKey => @"The given key '{0}' was not present in the dictionary.";
+    }
+}

+ 169 - 0
src/System.Collections/Resources/Strings.resx

@@ -0,0 +1,169 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <data name="Arg_NonZeroLowerBound" xml:space="preserve">
+    <value>The lower bound of target array must be zero.</value>
+  </data>
+  <data name="Arg_WrongType" xml:space="preserve">
+    <value>The value '{0}' is not of type '{1}' and cannot be used in this generic collection.</value>
+  </data>
+  <data name="Arg_ArrayPlusOffTooSmall" xml:space="preserve">
+    <value>Destination array is not long enough to copy all the items in the collection. Check array index and length.</value>
+  </data>
+  <data name="ArgumentOutOfRange_NeedNonNegNum" xml:space="preserve">
+    <value>Non-negative number required.</value>
+  </data>
+  <data name="ArgumentOutOfRange_SmallCapacity" xml:space="preserve">
+    <value>capacity was less than the current size.</value>
+  </data>
+  <data name="Argument_InvalidOffLen" xml:space="preserve">
+    <value>Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.</value>
+  </data>
+  <data name="Argument_AddingDuplicate" xml:space="preserve">
+    <value>An item with the same key has already been added. Key: {0}</value>
+  </data>
+  <data name="InvalidOperation_ConcurrentOperationsNotSupported" xml:space="preserve">
+    <value>Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.</value>
+  </data>
+  <data name="InvalidOperation_EmptyQueue" xml:space="preserve">
+    <value>Queue empty.</value>
+  </data>
+  <data name="InvalidOperation_EnumOpCantHappen" xml:space="preserve">
+    <value>Enumeration has either not started or has already finished.</value>
+  </data>
+  <data name="InvalidOperation_EnumFailedVersion" xml:space="preserve">
+    <value>Collection was modified; enumeration operation may not execute.</value>
+  </data>
+  <data name="InvalidOperation_EmptyStack" xml:space="preserve">
+    <value>Stack empty.</value>
+  </data>
+  <data name="InvalidOperation_EnumNotStarted" xml:space="preserve">
+    <value>Enumeration has not started. Call MoveNext.</value>
+  </data>
+  <data name="InvalidOperation_EnumEnded" xml:space="preserve">
+    <value>Enumeration already finished.</value>
+  </data>
+  <data name="NotSupported_KeyCollectionSet" xml:space="preserve">
+    <value>Mutating a key collection derived from a dictionary is not allowed.</value>
+  </data>
+  <data name="NotSupported_ValueCollectionSet" xml:space="preserve">
+    <value>Mutating a value collection derived from a dictionary is not allowed.</value>
+  </data>
+  <data name="Arg_ArrayLengthsDiffer" xml:space="preserve">
+    <value>Array lengths must be the same.</value>
+  </data>
+  <data name="Arg_BitArrayTypeUnsupported" xml:space="preserve">
+    <value>Only supported array types for CopyTo on BitArrays are Boolean[], Int32[] and Byte[].</value>
+  </data>
+  <data name="Arg_HSCapacityOverflow" xml:space="preserve">
+    <value>HashSet capacity is too big.</value>
+  </data>
+  <data name="Arg_HTCapacityOverflow" xml:space="preserve">
+    <value>Hashtable's capacity overflowed and went negative. Check load factor, capacity and the current size of the table.</value>
+  </data>
+  <data name="Arg_InsufficientSpace" xml:space="preserve">
+    <value>Insufficient space in the target location to copy the information.</value>
+  </data>
+  <data name="Arg_RankMultiDimNotSupported" xml:space="preserve">
+    <value>Only single dimensional arrays are supported for the requested action.</value>
+  </data>
+  <data name="Argument_ArrayTooLarge" xml:space="preserve">
+    <value>The input array length must not exceed Int32.MaxValue / {0}. Otherwise BitArray.Length would exceed Int32.MaxValue.</value>
+  </data>
+  <data name="Argument_InvalidArrayType" xml:space="preserve">
+    <value>Target array type is not compatible with the type of items in the collection.</value>
+  </data>
+  <data name="ArgumentOutOfRange_BiggerThanCollection" xml:space="preserve">
+    <value>Must be less than or equal to the size of the collection.</value>
+  </data>
+  <data name="ArgumentOutOfRange_Index" xml:space="preserve">
+    <value>Index was out of range. Must be non-negative and less than the size of the collection.</value>
+  </data>
+  <data name="ExternalLinkedListNode" xml:space="preserve">
+    <value>The LinkedList node does not belong to current LinkedList.</value>
+  </data>
+  <data name="LinkedListEmpty" xml:space="preserve">
+    <value>The LinkedList is empty.</value>
+  </data>
+  <data name="LinkedListNodeIsAttached" xml:space="preserve">
+    <value>The LinkedList node already belongs to a LinkedList.</value>
+  </data>
+  <data name="NotSupported_SortedListNestedWrite" xml:space="preserve">
+    <value>This operation is not supported on SortedList nested types because they require modifying the original SortedList.</value>
+  </data>
+  <data name="SortedSet_LowerValueGreaterThanUpperValue" xml:space="preserve">
+    <value>Must be less than or equal to upperValue.</value>
+  </data>
+  <data name="Serialization_InvalidOnDeser" xml:space="preserve">
+    <value>OnDeserialization method was called while the object was not being deserialized.</value>
+  </data>
+  <data name="Serialization_MismatchedCount" xml:space="preserve">
+    <value>The serialized Count information doesn't match the number of items.</value>
+  </data>
+  <data name="Serialization_MissingKeys" xml:space="preserve">
+    <value>The keys for this dictionary are missing.</value>
+  </data>
+  <data name="Serialization_MissingValues" xml:space="preserve">
+    <value>The values for this dictionary are missing.</value>
+  </data>
+  <data name="Arg_KeyNotFoundWithKey" xml:space="preserve">
+    <value>The given key '{0}' was not present in the dictionary.</value>
+  </data>
+</root>

+ 8 - 1
src/System.Collections/System.Collections.csproj

@@ -10,7 +10,14 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <ProjectReference Include="..\System.Private.CorLib\System.Private.CorLib.csproj" />
+    <None Include="Resources\Strings.resx">
+      <GenerateSource>true</GenerateSource>
+      <ClassName>System.SR</ClassName>
+    </None>
+  </ItemGroup>
+
+  <ItemGroup>
+    <ProjectReference Include="..\System.Private.CoreLib\System.Private.CoreLib.csproj" />
   </ItemGroup>
 
 </Project>

+ 1 - 1
src/System.Collections/TypeForwards.cs

@@ -6,4 +6,4 @@ using System.Runtime.CompilerServices;
 [assembly: TypeForwardedTo(typeof(List<>))]
 [assembly: TypeForwardedTo(typeof(Comparer<>))]
 [assembly: TypeForwardedTo(typeof(EqualityComparer<>))]
-[assembly: AssemblyEmbeddedCode("namespace System { namespace Collections { namespace Generic { template <class T0> using List_1_Enumerator = ::System_Private_CorLib::System::Collections::Generic::List_1_Enumerator<T0>; } } }")]
+[assembly: AssemblyEmbeddedCode("namespace System { namespace Collections { namespace Generic { template <class T0> using List_1_Enumerator = ::System_Private_CoreLib::System::Collections::Generic::List_1_Enumerator<T0>; } } }")]

+ 1 - 1
src/System.Diagnostics.Debug/System.Diagnostics.Debug.csproj

@@ -10,7 +10,7 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <ProjectReference Include="..\System.Private.CorLib\System.Private.CorLib.csproj" />
+    <ProjectReference Include="..\System.Private.CoreLib\System.Private.CoreLib.csproj" />
   </ItemGroup>
 
 </Project>

+ 1 - 1
src/System.Memory/System.Memory.csproj

@@ -10,7 +10,7 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <ProjectReference Include="..\System.Private.CorLib\System.Private.CorLib.csproj" />
+    <ProjectReference Include="..\System.Private.CoreLib\System.Private.CoreLib.csproj" />
   </ItemGroup>
 
 </Project>

+ 0 - 3
src/System.Private.CorLib/Properties/AssemblyInfo.cs

@@ -1,3 +0,0 @@
-using System;
-
-[assembly: CLSCompliant(true)]

+ 0 - 0
src/System.Private.CorLib/Internal/System/Runtime/CompilerServices/Unsafe.cs → src/System.Private.CoreLib/Internal/System/Runtime/CompilerServices/Unsafe.cs


+ 0 - 0
src/System.Private.CorLib/Natsu/AssemblyEmbeddedCodeAttribute.cs → src/System.Private.CoreLib/Natsu/AssemblyEmbeddedCodeAttribute.cs


+ 4 - 0
src/System.Private.CoreLib/Properties/AssemblyInfo.cs

@@ -0,0 +1,4 @@
+using System;
+using System.Reflection;
+
+[assembly: CLSCompliant(true)]

+ 0 - 0
src/System.Private.CorLib/Resources/Strings.Designer.cs → src/System.Private.CoreLib/Resources/Strings.Designer.cs


+ 0 - 0
src/System.Private.CorLib/Resources/Strings.resx → src/System.Private.CoreLib/Resources/Strings.resx


+ 1 - 1
src/System.Private.CorLib/System.Private.CorLib.csproj → src/System.Private.CoreLib/System.Private.CoreLib.csproj

@@ -3,7 +3,7 @@
     <OutputType>Library</OutputType>
     <TargetFramework>netcoreapp3.0</TargetFramework>
     <RootNamespace></RootNamespace>
-    <AssemblyName>System.Private.CorLib</AssemblyName>
+    <AssemblyName>System.Private.CoreLib</AssemblyName>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
     <LangVersion>8.0</LangVersion>
     <RuntimeMetadataVersion>v4.0.30319</RuntimeMetadataVersion>

+ 0 - 0
src/System.Private.CorLib/System.Private.CorLib.csproj.user → src/System.Private.CoreLib/System.Private.CoreLib.csproj.user


+ 0 - 0
src/System.Private.CorLib/System/Action.cs → src/System.Private.CoreLib/System/Action.cs


+ 0 - 0
src/System.Private.CorLib/System/ArgumentException.cs → src/System.Private.CoreLib/System/ArgumentException.cs


+ 0 - 0
src/System.Private.CorLib/System/ArgumentNullException.cs → src/System.Private.CoreLib/System/ArgumentNullException.cs


+ 0 - 0
src/System.Private.CorLib/System/ArgumentOutOfRangeException.cs → src/System.Private.CoreLib/System/ArgumentOutOfRangeException.cs


+ 0 - 0
src/System.Private.CorLib/System/ArithmeticException.cs → src/System.Private.CoreLib/System/ArithmeticException.cs


+ 0 - 0
src/System.Private.CorLib/System/Array.cs → src/System.Private.CoreLib/System/Array.cs


+ 0 - 0
src/System.Private.CorLib/System/ArraySegment.cs → src/System.Private.CoreLib/System/ArraySegment.cs


+ 0 - 0
src/System.Private.CorLib/System/ArrayTypeMismatchException.cs → src/System.Private.CoreLib/System/ArrayTypeMismatchException.cs


+ 0 - 0
src/System.Private.CorLib/System/Attribute.cs → src/System.Private.CoreLib/System/Attribute.cs


+ 0 - 0
src/System.Private.CorLib/System/AttributeTargets.cs → src/System.Private.CoreLib/System/AttributeTargets.cs


+ 0 - 0
src/System.Private.CorLib/System/AttributeUsageAttribute.cs → src/System.Private.CoreLib/System/AttributeUsageAttribute.cs


+ 0 - 0
src/System.Private.CorLib/System/BitConverter.cs → src/System.Private.CoreLib/System/BitConverter.cs


+ 0 - 0
src/System.Private.CorLib/System/Boolean.cs → src/System.Private.CoreLib/System/Boolean.cs


+ 0 - 0
src/System.Private.CorLib/System/Buffer.cs → src/System.Private.CoreLib/System/Buffer.cs


+ 0 - 0
src/System.Private.CorLib/System/Buffers/IMemoryOwner.cs → src/System.Private.CoreLib/System/Buffers/IMemoryOwner.cs


+ 0 - 0
src/System.Private.CorLib/System/Buffers/MemoryManager.cs → src/System.Private.CoreLib/System/Buffers/MemoryManager.cs


+ 0 - 0
src/System.Private.CorLib/System/Buffers/Text/FormattingHelpers.CountDigits.cs → src/System.Private.CoreLib/System/Buffers/Text/FormattingHelpers.CountDigits.cs


+ 0 - 0
src/System.Private.CorLib/System/ByReference.cs → src/System.Private.CoreLib/System/ByReference.cs


+ 0 - 0
src/System.Private.CorLib/System/Byte.cs → src/System.Private.CoreLib/System/Byte.cs


+ 0 - 0
src/System.Private.CorLib/System/CLSCompliantAttribute.cs → src/System.Private.CoreLib/System/CLSCompliantAttribute.cs


+ 0 - 0
src/System.Private.CorLib/System/Char.cs → src/System.Private.CoreLib/System/Char.cs


+ 0 - 0
src/System.Private.CorLib/System/CharEnumerator.cs → src/System.Private.CoreLib/System/CharEnumerator.cs


+ 0 - 0
src/System.Private.CorLib/System/Collections/Comparer.cs → src/System.Private.CoreLib/System/Collections/Comparer.cs


+ 0 - 0
src/System.Private.CorLib/System/Collections/Generic/ArraySortHelper.NatsuCLR.cs → src/System.Private.CoreLib/System/Collections/Generic/ArraySortHelper.NatsuCLR.cs


+ 0 - 0
src/System.Private.CorLib/System/Collections/Generic/ArraySortHelper.cs → src/System.Private.CoreLib/System/Collections/Generic/ArraySortHelper.cs


+ 0 - 0
src/System.Private.CorLib/System/Collections/Generic/Comparer.NatsuCLR.cs → src/System.Private.CoreLib/System/Collections/Generic/Comparer.NatsuCLR.cs


+ 0 - 0
src/System.Private.CorLib/System/Collections/Generic/Comparer.cs → src/System.Private.CoreLib/System/Collections/Generic/Comparer.cs


+ 0 - 0
src/System.Private.CorLib/System/Collections/Generic/ComparerHelpers.cs → src/System.Private.CoreLib/System/Collections/Generic/ComparerHelpers.cs


+ 0 - 0
src/System.Private.CorLib/System/Collections/Generic/EqualityComparer.NatsuCLR.cs → src/System.Private.CoreLib/System/Collections/Generic/EqualityComparer.NatsuCLR.cs


+ 0 - 0
src/System.Private.CorLib/System/Collections/Generic/EqualityComparer.cs → src/System.Private.CoreLib/System/Collections/Generic/EqualityComparer.cs


+ 0 - 0
src/System.Private.CorLib/System/Collections/Generic/ICollection.cs → src/System.Private.CoreLib/System/Collections/Generic/ICollection.cs


+ 0 - 0
src/System.Private.CorLib/System/Collections/Generic/ICollectionDebugView.cs → src/System.Private.CoreLib/System/Collections/Generic/ICollectionDebugView.cs


+ 0 - 0
src/System.Private.CorLib/System/Collections/Generic/IComparer.cs → src/System.Private.CoreLib/System/Collections/Generic/IComparer.cs


+ 0 - 0
src/System.Private.CorLib/System/Collections/Generic/IEnumerable.cs → src/System.Private.CoreLib/System/Collections/Generic/IEnumerable.cs


+ 0 - 0
src/System.Private.CorLib/System/Collections/Generic/IEnumerator.cs → src/System.Private.CoreLib/System/Collections/Generic/IEnumerator.cs


+ 0 - 0
src/System.Private.CorLib/System/Collections/Generic/IEqualityComparer.cs → src/System.Private.CoreLib/System/Collections/Generic/IEqualityComparer.cs


+ 0 - 0
src/System.Private.CorLib/System/Collections/Generic/IList.cs → src/System.Private.CoreLib/System/Collections/Generic/IList.cs


+ 0 - 0
src/System.Private.CorLib/System/Collections/Generic/IReadOnlyCollection.cs → src/System.Private.CoreLib/System/Collections/Generic/IReadOnlyCollection.cs


+ 0 - 0
src/System.Private.CorLib/System/Collections/Generic/IReadOnlyList.cs → src/System.Private.CoreLib/System/Collections/Generic/IReadOnlyList.cs


+ 0 - 0
src/System.Private.CorLib/System/Collections/Generic/KeyNotFoundException.cs → src/System.Private.CoreLib/System/Collections/Generic/KeyNotFoundException.cs


+ 0 - 0
src/System.Private.CorLib/System/Collections/Generic/List.cs → src/System.Private.CoreLib/System/Collections/Generic/List.cs


+ 0 - 0
src/System.Private.CorLib/System/Collections/IComparer.cs → src/System.Private.CoreLib/System/Collections/IComparer.cs


+ 0 - 0
src/System.Private.CorLib/System/Collections/IEqualityComparer.cs → src/System.Private.CoreLib/System/Collections/IEqualityComparer.cs


+ 0 - 0
src/System.Private.CorLib/System/Collections/IStructuralComparable.cs → src/System.Private.CoreLib/System/Collections/IStructuralComparable.cs


+ 0 - 0
src/System.Private.CorLib/System/Collections/IStructuralEquatable.cs → src/System.Private.CoreLib/System/Collections/IStructuralEquatable.cs


+ 0 - 0
src/System.Private.CorLib/System/ComponentModel/EditorBrowsableAttribute.cs → src/System.Private.CoreLib/System/ComponentModel/EditorBrowsableAttribute.cs


+ 0 - 0
src/System.Private.CorLib/System/Console.cs → src/System.Private.CoreLib/System/Console.cs


+ 0 - 0
src/System.Private.CorLib/System/Delegate.cs → src/System.Private.CoreLib/System/Delegate.cs


+ 0 - 0
src/System.Private.CorLib/System/Diagnostics/CodeAnalysis/NullableAttributes.cs → src/System.Private.CoreLib/System/Diagnostics/CodeAnalysis/NullableAttributes.cs


+ 0 - 0
src/System.Private.CorLib/System/Diagnostics/CodeAnalysis/SuppressMessageAttribute.cs → src/System.Private.CoreLib/System/Diagnostics/CodeAnalysis/SuppressMessageAttribute.cs


+ 0 - 0
src/System.Private.CorLib/System/Diagnostics/ConditionalAttribute.cs → src/System.Private.CoreLib/System/Diagnostics/ConditionalAttribute.cs


+ 0 - 0
src/System.Private.CorLib/System/Diagnostics/Debug.cs → src/System.Private.CoreLib/System/Diagnostics/Debug.cs


+ 0 - 0
src/System.Private.CorLib/System/Diagnostics/DebuggerBrowsableAttribute.cs → src/System.Private.CoreLib/System/Diagnostics/DebuggerBrowsableAttribute.cs


+ 0 - 0
src/System.Private.CorLib/System/Diagnostics/DebuggerDisplayAttribute.cs → src/System.Private.CoreLib/System/Diagnostics/DebuggerDisplayAttribute.cs


+ 0 - 0
src/System.Private.CorLib/System/Diagnostics/DebuggerHiddenAttribute.cs → src/System.Private.CoreLib/System/Diagnostics/DebuggerHiddenAttribute.cs


+ 0 - 0
src/System.Private.CorLib/System/Diagnostics/DebuggerNonUserCodeAttribute.cs → src/System.Private.CoreLib/System/Diagnostics/DebuggerNonUserCodeAttribute.cs


+ 0 - 0
src/System.Private.CorLib/System/Diagnostics/DebuggerTypeProxyAttribute.cs → src/System.Private.CoreLib/System/Diagnostics/DebuggerTypeProxyAttribute.cs


+ 0 - 0
src/System.Private.CorLib/System/Diagnostics/StackTraceHiddenAttribute.cs → src/System.Private.CoreLib/System/Diagnostics/StackTraceHiddenAttribute.cs


+ 0 - 0
src/System.Private.CorLib/System/Double.cs → src/System.Private.CoreLib/System/Double.cs


+ 0 - 0
src/System.Private.CorLib/System/Enum.cs → src/System.Private.CoreLib/System/Enum.cs


+ 0 - 0
src/System.Private.CorLib/System/Environment.cs → src/System.Private.CoreLib/System/Environment.cs


Неке датотеке нису приказане због велике количине промена