Skip to content

Commit 98b5f11

Browse files
committed
Merge branch 'master' of https://github.com/TheFocusMan/Cosmos
2 parents 361bfdb + bb84670 commit 98b5f11

File tree

7 files changed

+113
-4
lines changed

7 files changed

+113
-4
lines changed

Tests/Kernels/Cosmos.Compiler.Tests.TypeSystem/Kernel.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ private void TestVTablesImpl()
8989
Assert.AreEqual(((CosmosRuntimeType)typeof(object)).mTypeId, types[0], "GetGCFieldTypes returns object at offset 0");
9090
Assert.AreEqual(((CosmosRuntimeType)typeof(TestStruct)).mTypeId, types[1], "GetGCFieldTypes returns TestStruct at offset 1");
9191
Assert.AreEqual(((CosmosRuntimeType)typeof(object)).mTypeId, types[2], "GetGCFieldTypes returns object at offset 2");
92+
93+
// check that classes have the correct name
94+
Assert.AreEqual("Int32", ((CosmosRuntimeType)typeof(int)).Name, "Name of Int32 is correctly stored");
95+
Assert.AreEqual("Object", ((CosmosRuntimeType)typeof(object)).Name, "Name of Object is correctly stored");
9296
}
9397

9498
private unsafe void TestGarbageCollectorMethods()
@@ -139,6 +143,7 @@ private unsafe void TestGarbageCollector()
139143
Assert.AreEqual(0, collected, "Storing elements in static class keeps them referenced");
140144
}
141145

146+
#region Test Methods
142147
public void TestMethod1()
143148
{
144149
object a = new object();
@@ -208,6 +213,8 @@ void TestMethod6()
208213
Console.WriteLine("Test: " + 3 + " vs " + 5);
209214
}
210215

216+
#endregion
217+
211218
protected override void Run()
212219
{
213220
try
@@ -262,6 +269,7 @@ protected override void Run()
262269
TestGarbageCollectorMethods();
263270
TestGarbageCollector();
264271
RealMethodsTest();
272+
TestReflection();
265273

266274
TestController.Completed();
267275
}
@@ -276,5 +284,20 @@ protected override void Run()
276284
TestController.Failed();
277285
}
278286
}
287+
288+
private static void TestReflection()
289+
{
290+
Assert.AreEqual("Int32", typeof(int).Name, "Plug for Name of Int32 works");
291+
Assert.AreEqual("Object", typeof(object).Name, "Plug for Name of Object works");
292+
string intAQN = typeof(int).AssemblyQualifiedName;
293+
Assert.IsTrue(intAQN.StartsWith("System.Int32, System.Private.CoreLib"), $"Plug for AssemblyQualifiedName of Int32 works ({intAQN})");
294+
string objectAQN = typeof(object).AssemblyQualifiedName;
295+
Assert.IsTrue(objectAQN.StartsWith("System.Object, System.Private.CoreLib"), $"Plug for AssemblyQualifiedName of Object works ({objectAQN})");
296+
297+
Assert.AreEqual("Int32", Type.GetType("Int32").Name, "GetType works on Int32");
298+
Assert.AreEqual("Int32", Type.GetType(typeof(int).AssemblyQualifiedName).Name, "GetType works on Int32 using assembly qualified name");
299+
Assert.AreEqual("Int32", Type.GetType("System.Int32, System.Private.CoreLib").Name, "GetType works on Int32 with shortened assembly qualified name");
300+
Assert.AreEqual("Int32", Type.GetType("System.Int32").Name, "GetType works on Int32 with shortened assembly qualified name");
301+
}
279302
}
280303
}

source/Cosmos.Build.Tasks/IL2CPU.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public class IL2CPU : ToolTask
5656

5757
public bool RemoveBootDebugOutput { get; set; }
5858

59+
public bool AllowComments { get; set; }
60+
5961
public string VBEResolution { get; set; }
6062

6163
#endregion
@@ -68,6 +70,7 @@ public class IL2CPU : ToolTask
6870
public IL2CPU()
6971
{
7072
CompileVBEMultiboot = false;
73+
AllowComments = false;
7174
VBEResolution = "800x600x32";
7275
}
7376

@@ -99,7 +102,8 @@ protected override string GenerateResponseFileCommands()
99102
["IgnoreDebugStubAttribute"] = IgnoreDebugStubAttribute.ToString(),
100103
["CompileVBEMultiboot"] = CompileVBEMultiboot.ToString(),
101104
["VBEResolution"] = VBEResolution.ToString(),
102-
["RemoveBootDebugOutput"] = RemoveBootDebugOutput.ToString()
105+
["RemoveBootDebugOutput"] = RemoveBootDebugOutput.ToString(),
106+
["AllowComments"] = AllowComments.ToString()
103107
}.ToList();
104108

105109
foreach (var reference in References)

source/Cosmos.Build.Tasks/build/Cosmos.Build.targets

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272

7373
<RemoveBootDebugOutput Condition="'$(RemoveBootDebugOutput)' == ''">ELF</RemoveBootDebugOutput>
7474

75+
<AllowComments Condition="'$(AllowComments)' == ''">False</AllowComments>
76+
7577
<OptimizationLevel Condition="'$(OptimizationLevel)' == ''">1</OptimizationLevel>
7678
</PropertyGroup>
7779

@@ -205,7 +207,8 @@
205207
ToolPath="$(Il2cpuToolPath)"
206208
ToolExe="$(Il2cpuToolExe)"
207209
CompileVBEMultiboot="$(CompileVBEMultiboot)"
208-
VBEResolution="$(VBEResolution)"/>
210+
AllowComments="$(AllowComments)"
211+
VBEResolution="$(VBEResolution)"/>
209212

210213
</Target>
211214

source/Cosmos.Core/VTablesImpl.cs

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ public static bool IsInstance(uint aObjectType, uint aDesiredObjectType, bool aI
9494

9595
public static void SetTypeInfo(int aType, uint aBaseType, uint aSize, uint aInterfaceCount, uint[] aInterfaceIndexes,
9696
uint aMethodCount, uint[] aMethodIndexes, uint[] aMethodAddresses,
97-
uint aInterfaceMethodCount, uint[] aInterfaceMethodIndexes, uint[] aTargetMethodIndexes, uint aGCFieldCount, uint[] aGCFieldOffsets, uint[] aGCFieldTypes,
98-
bool aIsValueType, bool aIsStruct)
97+
uint aInterfaceMethodCount, uint[] aInterfaceMethodIndexes, uint[] aTargetMethodIndexes, uint aGCFieldCount,
98+
uint[] aGCFieldOffsets, uint[] aGCFieldTypes, bool aIsValueType, bool aIsStruct, string aName, string aAssemblyQualifiedName)
9999
{
100100
var vTable = new VTable();
101101
vTable.BaseTypeIdentifier = aBaseType;
@@ -110,6 +110,8 @@ public static void SetTypeInfo(int aType, uint aBaseType, uint aSize, uint aInte
110110
vTable.TargetMethodIndexes = aTargetMethodIndexes;
111111
vTable.IsValueType = aIsValueType;
112112
vTable.IsStruct = aIsStruct;
113+
vTable.Name = aName;
114+
vTable.AssemblyQualifiedName = aAssemblyQualifiedName;
113115
mTypes[aType] = vTable;
114116
var gcTable = new GCTable();
115117
gcTable.GCFieldCount = aGCFieldCount;
@@ -341,10 +343,68 @@ public static bool IsStruct(uint aType)
341343
{
342344
return mTypes[aType].IsStruct;
343345
}
346+
347+
/// <summary>
348+
/// Gets the Name of the type
349+
/// </summary>
350+
/// <param name="aType"></param>
351+
/// <returns></returns>
352+
public static string GetName(uint aType)
353+
{
354+
return mTypes[aType].Name;
355+
}
356+
357+
/// <summary>
358+
/// Gets the Assembly Qualified Name for the type
359+
/// </summary>
360+
/// <param name="aType"></param>
361+
/// <returns></returns>
362+
public static string GetAssemblyQualifiedName(uint aType)
363+
{
364+
return mTypes[aType].AssemblyQualifiedName;
365+
}
366+
367+
/// <summary>
368+
/// Get type id of type matching the name
369+
/// The name can either be name of the class or the assembly qualified name
370+
/// Only inlcuding the first or first two parts of the assembly qualified name also works
371+
/// </summary>
372+
/// <param name="name"></param>
373+
/// <returns>Returns -1 if no type can be found</returns>
374+
public static int GetType(string name)
375+
{
376+
for (int i = 0; i < mTypes.Length; i++)
377+
{
378+
var currType = mTypes[i];
379+
if (currType.Name == name || currType.AssemblyQualifiedName == name)
380+
{
381+
return i;
382+
}
383+
else
384+
{
385+
bool difference = false;
386+
for (int k = 0; k < name.Length; k++)
387+
{
388+
if (name[k] != currType.AssemblyQualifiedName[k])
389+
{
390+
difference = true;
391+
break;
392+
}
393+
}
394+
if (!difference)
395+
{
396+
return i;
397+
}
398+
}
399+
}
400+
return -1;
401+
}
344402
}
345403

346404
public struct VTable
347405
{
406+
public string Name;
407+
public string AssemblyQualifiedName;
348408
public uint BaseTypeIdentifier;
349409
public uint Size;
350410

source/Cosmos.Core_Plugs/System/TypeImpl.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,16 @@ public static Type get_BaseType(CosmosRuntimeType aThis)
7171
{
7272
return aThis.BaseType;
7373
}
74+
75+
[PlugMethod(Signature = "System_Type__System_Type_get_Type_System_String", IsOptional = false)]
76+
public static CosmosRuntimeType GetType(string aName)
77+
{
78+
int typeId = VTablesImpl.GetType(aName);
79+
if(typeId == -1)
80+
{
81+
return null;
82+
}
83+
return new CosmosRuntimeType((uint)typeId);
84+
}
7485
}
7586
}

source/Cosmos.Debug.Hosts/VMware.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
using System.Collections.Generic;
33
using System.Diagnostics;
44
using System.IO;
5+
using System.Linq;
56
using System.Text;
7+
using System.Threading;
68
using Microsoft.Win32;
79

810
//using Vestris.VMWareLib;

source/Cosmos.VS.ProjectSystem/BuildSystem/Rules/CosmosPropertyPage.xaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@
6868
Category="Compile">
6969
</BoolProperty>
7070

71+
<BoolProperty Name="AllowComments"
72+
DisplayName="Allow X# Comments"
73+
Description="Include comments in the final assembly. Enabling this will increase compile times."
74+
Category="Compile">
75+
</BoolProperty>
76+
7177
<EnumProperty Name="OptimizationLevel"
7278
DisplayName="Optimization Level"
7379
Description="Choose the optimization level that you want to use."

0 commit comments

Comments
 (0)